Solve the following problems in Haskell.
What are the values of these expressions?
foldl (-) 0 [1, 2, 3]
foldr (-) 0 [1, 2, 3]
What are the types of foldl
and foldr
?
Write foldl
and foldr
.
foldl1
and foldr1
are versions of foldl
and foldr
that take no accumulator argument: they simply
apply a binary operator to all elements in a list. They cannot be
applied to empty lists. For example,
foldl1 (+) [1, 2, 3] == 6 foldr1 (+) [1, 2, 3] == 6
What are the types of foldl1
and foldr1
?
Write these functions.