4

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?

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

Comments

7
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.