To answer this question, it’s good to remember what foldrand do map.
The more complex of the two is foldrwhich is of type
-- list to be folded
-- v
foldr :: (a -> b -> b) -> b -> [a] -> b
-- ^ ^
--folding function terminal value
A folded list really is a chain of conses (:)and an empty list of terminals:
1 : 2 : 3 : []
The action foldris the replacement of designers :and []folding function and the terminal value, respectively:
foldr (+) 0 (1 : 2 : 3 : []) == 1 + 2 + 3 + 0
map . - :
map :: (a -> b) -> [a] -> [b]
-- ^ ^
-- function list
, , :
map :: (a -> b) -> ( [a] -> [b] )
-- ^ ^
-- function function on lists
, map . foldr? , - ,
(map . foldr) f == map (foldr f)
foldr, f :: a -> b -> b, :
foldr f :: b -> [a] -> b
-- ^ ^
--terminal val list to be folded
map, , :
map (foldr f) :: [b] -> [[a] -> b]
-- ^ ^
--list of terminal vals functions that fold lists
, . , - .
, (+),
(+) :: Num a => a -> a -> a
,
(map . foldr) (+) :: Num a => [a] -> [[a] -> a]
-- ^ ^
-- list of terminal vals functions that fold lists
[0, 1, 2], :
(map . foldr) (+) [0,1,2] :: Num a => [[a] -> a]
map ($x), . , [3,4,5]. :
> map ($[3,4,5]) ((map.foldr) (+) [0,1,2])
[12, 13, 14]
[3,4,5] , (+) , :
3 + 4 + 5 + 0 == 12
3 + 4 + 5 + 1 == 13
3 + 4 + 5 + 2 == 14
0, : 3 + 4 + 5 == 12. 1, , (13), 2, (14).