Proposal #3999: Improved folds for Data.Map and Data.IntMap

Heinrich Apfelmus apfelmus at quantentunnel.de
Fri Apr 23 05:45:09 EDT 2010


Roman Leshchinskiy wrote:
> Hmm, I'd love to see some real-world uses of foldl. I have no idea
> what to optimise it for in vector. Unfortunately, the link above
> doesn't give any examples.

Here a use of foldl from the Haskell98 Prelude:

    reverse :: [a] -> [a]
    reverse = foldl (flip (:)) []

Basically, foldl is useful if the accumulating parameter uses equal or
more space if evaluated to normal form than the input list.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



More information about the Libraries mailing list