September 2017
Beginner to intermediate
396 pages
9h 46m
English
Foldr has a type declaration as shown here:
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
Whereas, foldl has a type declaration as shown here:
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
The part of the declaration Foldable t denotes that folds can be implemented by any data type that would declare itself to be Foldable (Foldable is a type class). In the context of list, the preceding function can be adapted as follows:
foldr :: (a -> b -> b) -> b -> [a] -> b foldl :: (b -> a -> b) -> b -> [a] -> b
Foldr takes three arguments, which are described here:
Read now
Unlock full access