Proposal: alpha-rename the type signatures of foldl, foldl', and scanl to be consistent with foldr and scanr

Henning Thielemann lemming at henning-thielemann.de
Mon Oct 15 19:00:40 CEST 2012


I like to add that if you define a class for structures and according 
element types that support both foldl and foldr, and you are not using the 
RMonad trick, then the name of the types really matter:

class Foldable v a b where
    foldl :: (a -> b -> a) -> a -> v b -> a
    foldr :: (a -> b -> b) -> b -> v a -> b

The accumulator type would not need to be storable in the structure 'v' 
but if the Fold class uses the variable names from the Prelude then both 
accumulator and element type are constrained.

I think the accumulator should not be named 'r' because there are many 
result types in the List module that are not named 'r' and should not be, 
for instance because argument and result have the same type or are just 
Int or Bool. The distinguishing feature of a result type is that it is the 
last type in a chain of arrows, but you can hardly express this using the 
variable name.



More information about the Libraries mailing list