Reputation: 841
I am currently learning haskell and struggling with the following test : Suppose we have such a type :
type Endo a = a -> a
I have to choose all types that are equivalent to Endo (Endo Int)
(Int -> Int) -> (Int -> Int)
(Int -> Int) -> Int -> Int
Int
Int -> Int
Int -> Int -> Int -> Int
(Int -> Int) -> Int
Int -> Int -> (Int -> Int)
Int -> (Int -> Int)
Int -> Int -> Int
Since the type of Endo Int
is Int -> Int
I understand that type I need has 4 Ints such as (Int -> Int) -> (Int -> Int)
.
But I do not really understand which parenthesis are unnecessary
Upvotes: 1
Views: 1636
Reputation: 15278
It is right associative in Haskell, so following are equivalent:
a -> b -> c
a -> (b -> c)
Function that takes arguments a and b is equivalent to function that given argument a returns function that takes argument b.
It is not left associative.
So the answer is first two.
Upvotes: 5
Reputation: 116139
Your intuition is correct: (Int -> Int) -> (Int -> Int)
is indeed Endo (Endo Int)
.
Just recall that ->
associates on the right, i.e.
a -> b -> c means a -> (b -> c)
Given that, you should now be able to solve the exercise.
Upvotes: 0