I'm learning haskell and saw function compositions.
Tried to composite map and foldl
mapd = (map.foldl)
Than
test = (mapd (\x y -> x + y ) [1,2,3,4])
Type of test is
test :: [[Integer] -> Integer]
So what is this type declaration means?
That means that your function "test" returns a list of functions. And that each of those functions takes a list of integers and returns an integer.
test
= mapd (\x y -> x + y ) [1,2,3,4]
= mapd (+) [1,2,3,4]
= (map . foldl) (+) [1,2,3,4]
= map (foldl (+)) [1,2,3,4]
= [ foldl (+) 1
, foldl (+) 2
, foldl (+) 3
, foldl (+) 4 ]
The result is a list of functions. The first function takes a list of integers, and sums it up starting from 1. The second is similar, but starts from 2. And so on for the remaining functions.
As fgv already stated, this is a list of functions from list of integers to integer, hence the [[Integer] -> Integer] type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With