I'm having some difficulty using Turtle and only after several minutes staring at incomprehensible error messages realized that I was using wrong fold function.
https://hackage.haskell.org/package/turtle-1.5.8/docs/Turtle-Shell.html#v:fold https://hackage.haskell.org/package/foldl-1.4.0/docs/src/Control.Foldl.html#fold
Why is there a name collision? I don't believe that's coincidence but I cannot figure it out. Are these inherently different kinds of folds?
To be concrete, I wanted to fold a stream filenames into single name using maximum of modification time.
(First of all, the folds we are talking about here are not the foldr foldl foldl' functions from
Data.Foldable, they are from the foldl package, which is conceptually related to thefoldl'function from theData.Foldable, as a sort of versatile generalization, but has separate definitions.)The
Folddatatype repesents a strict, stateful operation to perform on an incoming sequence of values. ItsApplicativeinstance lets you run two operations combined on the same sequence of values.Folds have the nice property that they are agnostic about where the values come from.Each type of source will have its own function to feed in the values. These functions might share the name
fold, but it isn't a problem because the typical recommendation is to import the packages qualified.The fold function from the foldl package feeds the contents of any
Foldablecontainer. The fold from turtle feeds the results of aShell. Streaming libraries like "pipes" have their own adapters.