foldM_ f xs = fold (\a e -> a >> f e) (return ()) xs
Instead of making chain of dynamically created functions from data list it is better to create a function that makes next function in chain
foldM_ f l = foldLoop l
where
foldLoop [] = return ()
foldLoop [x:xs] = f x >> foldLoop xs
Notice that this fragment does not use any language laziness.
No comments:
Post a Comment