Mark all correct answers with an X. Note that any number of answers can be correct. Each question is worth 1.5 points. For each incorrect answer 0.5 points are deducted; negative scores for a question are not possible.

* Which of the following expressions will yield a type error?

[X] map (\ x -> if x then 32 else 42) [1, 2, 3]

[ ] Just [Nothing]

[ ] filter id [True, False, False, True]

[ ] [[1, 2], [1, 2, 3]]

[ ] ([42], False, True)

* Which of the following types are correct?

[X] putStrLn "Hello, world!" :: IO ()

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

[X] getLine :: IO String

[ ] filter :: (a -> b) -> [a] -> [b]

[ ] (>>) :: IO res1 -> res1 -> IO res2 -> IO res2

* Which of the following expressions terminate (if they are entered into ghci)?

[X] let listLoop = 1 : listLoop in take 42 listLoop

[ ] let noLoop = noLoop in take 12 noLoop

[ ] let boolLoop = boolLoop in True && boolLoop

[X] let boolLoop = boolLoop in True || boolLoop

[X] let noLoop = 1 : noLoop in zip noLoop [1,2,3,4,5]

* Which of the following expressions yield 6? (Remark: `const` has type `a -> b -> a`)

[X] length (zip [1,2,3,4,5,6] [1,2,3,4,5,6])

[ ] foldr (+) 6 [1,1,2,2]

[ ] const 42 6

[X] head (map (\x -> x * 2) [3,2,1])

[X] length (map (\x -> x + 1) [1,2,3,4,5,6])

* Which of the following types have exactly four different values?

[X] (Bool, Bool)

[ ] Either Bool ()

[ ] Maybe Bool

[ ] ((), Bool)

[X] Either Bool Bool

(1.5 points) What's the type of the following operations?

(>>) :: IO a -> IO b -> IO b

(>>=) :: IO a -> (a -> IO b) -> IO b

(1.5 points) Give the most general type signature for the following function.

>f::(a->c->d)->(a->b->c)->b->a->d

>fghxy=gy(hyx)

(1.5 points) We define the following algebraic data types and definitions.

>dataBoringwhere

>Boring::Boring

>

>dataExcitingawhere

>Ex1::ExcitingBoring->Excitinga

>Ex2::a->Excitinga

Give three different values of type `Exciting ()`.

>val1::Exciting()

>val1=Ex2()

>

>val2::Exciting()

>val2=Ex1(Ex2Boring)

>

>val3::Exciting()

>val3=E1(Ex1(Ex2Boring))

# 2 - A Lot of Definitions -- 16 Points

(3 points) Define a data type in GADT-syntax to represent a Boolean expression. The Boolean expression can be a truth value (true and false), a conjunction, or a negation.

>dataBoolExpwhere

>Val::Bool->BoolExp

>Conj::BoolExp->BoolExp->BoolExp

>Neg::BoolExp->BoolExp

>dataBoolExpAlternativewhere

>TTrue::BoolExmp

>FFalse::BoolExmp

>Conj::BoolExp->BoolExp->BoolExp

>Neg::BoolExp->BoolExp

(3 points) Consider the following types to represent a field of tokens.

>dataTokenwhere

>Blank::Token

>Block::Token

>

>-- The outer list represent the rows, and the inner list the columns of one row

>typeField=[[Token]]

>

>eqToken::Token->Token->Bool

>eqTokenBlankBlank=True

>eqTokenBlockBlock=True

>eqToken__=False

Define the following functions based on `Field`.

>-- Checks if the `Field` contains the given `Token`,

>-- yields `True` if the `Token` occurs and `False` otherwise.

(2 Points) Define a function `length` using `foldr` that computes the length of a list.

>length::[a]->Int

>lengthlist=foldrfConsfNillist

>where

>fCons=\_acc->1+acc

>fNil=0

(4 Points) Define a function `getStringWithAtLeastTwoVowels` that reads a string from the user and yields the user's input if it contains at least two vowels; otherwise the user should be informed of the missed criterion and get another try (until the given input meets the criterion). Don't forget to annotate all functions that you define with their type signatures as well.

>getStringWithAtLeastTwoVowels::IOString

>getStringWithAtLeastTwoVowels=

>getLine>>=\str->

>iflength(vowelsstr)>=2

>thenpurestr

>elseputStrLn"Your string should contain at least two vowels, please try again">>