Functional Programming (H) - 4.05 - Idiomatic Haskell
1.
let x = y + 2 y = x/3 in x+y
This code defines a pair of simultaneous equations. Will this work in Haskell?
yes — it will compute the two values that have mutually recursive definitions
no — it will either fail with an error or loop forever.
2. What is the missing case clause in the following definition of a function to calculate the length of a Haskell list?
mylength l = case l of -- MISSING CLAUSE -- x:xs -> 1+mylength xs
Null -> 0
[] -> 0
[] <- 0
3. In a Haskell guard expression, each of the guards evaluates to a Bool value, either True or False. What is the Bool value for the otherwise case?
Maybe True
True
False
4. Select which one of the following two let expressions will evaluate to the String
"prime minister"
let x = numeral ++ " minister" in x where numeral = "prime"
let x = numeral ++ " minister" where numeral = "prime" in x
5. Study the Haskell function f below. What does f() evaluate to?
f :: () -> String f () = let x = (Just Nothing) in case x of (Just _) -> "something" Nothing -> "nothing"
"nothing"
Nothing
"something"
Submit Quiz