[Haskell-beginners] Haskell type system

informationen informationen at gmx.de
Sun Sep 27 06:22:50 EDT 2009


Hi,

i am trying to understand the Haskell type system. I thought i understood it
quite well until i encountered the three following exercises. As you can see, i
have the answers already. But i don't understand, why they are correct.

Could anybody tell me a good place where i could learn how to answers these kind
of questions correctly or could give me some explanations, why these answers are
correct?

Any help is highly appreciated.

Kind regards

Chris 

Two functions f and g with the following signatures are given:
f :: a -> a
g :: b -> c -> b

A) Give the type of the following expressions:

1) g [False] True  :: 
2) g [] True       :: 
3) g (f True)      :: 
4) g f             :: 

Answers:

1 [Boolean] 
2) [a]          
3) c -> Bool
4) c -> (a -> a)1)  g f 1      

B) Which of the following statements is correct?

2)  g (f 1)         is type correct
3)  g . (f 1)       is type correct
4)  g . f 1         is type correct
5)  (g . f) 1       is type correct
6)                  none of the expressions is correct

Answers:
1,2 and 5 are correct.

C) A function h is given as: h p x = p (f x). Which of the following
statements is correct.

1) h :: a -> b -> a -> b
2) h :: (a -> a) -> a -> a
3) h :: (a -> b) -> a -> b
4) h is equivalent to h' with h' p = p . f
5) h is equivalent to h' with h' p = p f
5) h is equivalent to h' with h' p x = p f x

Answers:
(I am not sure, if i remember correctly, but 3) and 4) should be
correct.)




More information about the Beginners mailing list