Declaration of type [[Integer] & # 8594; Integer]

I study Haskell and have seen functional compositions. Tried to composite mapandfoldl

mapd = (map.foldl)

Than

test = (mapd (\x y -> x + y ) [1,2,3,4])

Test type

test :: [[Integer] -> Integer]

So what does an ad of this type mean?

+4
source share
2 answers

This means that your test function returns a list of functions. And that each of these functions takes a list of integers and returns an integer.

+10
source
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 at 1. The second is similar, but begins with 2. And so on for the rest of the functions.

fgv, integer, , [[Integer] -> Integer].

+7

All Articles