Why the Haskell sequence function can't be lazy or why recursive monadic functions can't be lazy
问题 With the question Listing all the contents of a directory by breadth-first order results in low efficiencyI learned that the low efficiency is due to a strange behavior of the recursive monad functions. Try sequence $ map return [1..]::[[Int]] sequence $ map return [1..]::Maybe [Int] and ghci will fall into an endless calculation. If we rewrite the sequence function in a more readable form like follows: sequence' [] = return [] sequence' (m:ms) = do {x<-m; xs<-sequence' ms; return (x:xs)} and