Haskell: Replace mapM in a monad transformer stack to achieve lazy evaluation (no space leaks)
问题 It has already been discussed that mapM is inherently not lazy, e.g. here and here. Now I'm struggling with a variation of this problem where the mapM in question is deep inside a monad transformer stack. Here's a function taken from a concrete, working (but space-leaking) example using LevelDB that I put on gist.github.com: -- read keys [1..n] from db at DirName and check that the values are correct doRead :: FilePath -> Int -> IO () doRead dirName n = do success <- runResourceT $ do db <-