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?
no — it will either fail with an error or loop forever.
yes — it will compute the two values that have mutually recursive definitions
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
[] <- 0
[] -> 0
Null -> 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?
False
Maybe True
True
4. Select which one of the following two let expressions will evaluate to the String
"prime minister"
let x = numeral ++ " minister" where numeral = "prime" in x
let x = numeral ++ " minister" in x where numeral = "prime"
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