joakimb
joakimb

Reputation: 563

What is the difference of types a->b and a->a1 in haskell

I am trying to understand the following type signature in Haskell:

map (const (++)) :: [a] -> [[a1] -> [a1] -> [a1]]

I understand that map will apply the function (const (++)) on every element in the array [a]. Is it correct to assume that when (const (++)) is applied to an array-member, that the array-member will get ignored by const and the entire function will output an array full of (++)? e.g:

[(++), (++), (++), ... , (++)]

Since (++) has the type signature [a] -> [a] -> [a], why isn't the type signature of the entire function:

map (const (++)) :: [a] -> [[a] -> [a] -> [a]]

or

map (const (++)) :: [a] -> [[b] -> [b] -> [b]]

?

what is the special meaning of 'a1'?

Upvotes: 1

Views: 394

Answers (2)

phiology
phiology

Reputation: 29

it is just a notation.

use of a1 instaed of say x is often used to make clear that the elements in the array of type [a] are the same as given to the function.

edit: was already answered before.

Upvotes: 1

adjan
adjan

Reputation: 13652

map is of type [a] -> [b]

and as you correctly pointed out, ++ is of type [a] -> [a] -> [a]

so the whole expression must be some sort of

[a] -> [[b] -> [b] -> [b]]

If you call b, a1 instead is just notation.

Upvotes: 3

Related Questions