Question: HASKELL MCQ Question 1 This question has 12 parts. Answer all parts. A) What is the type of the following expression? chr (head $ tail
HASKELL MCQ
Question 1 This question has 12 parts. Answer all parts.
A) What is the type of the following expression?
chr (head $ tail $ map (+1) $ filter even [1..10])
a. [Int]
b. Int
c. [Char]
d. Num a => [a]
e. Char
B) Given the following parentheses-free expression, which of the followingparenthesised expressions is the same?
a + b/c - d * f e g + h j
a. (a + b)/(c - d) * ((f e) g) + (h j)
b. (a + b)/((c - d) * f) (e g) + (h j)
c. a + (b/c) - (d * (f (e g)) + (h j))
d. a + (b/c) - (d * ((f e) g)) + (h j)
e. a + (b/c) - (d * (f e (g + h) j))
C) Which of the following expressions has a type error?
a. head [1,2,3] + 4
b. tail [1,2,3] ++ [4]
c. init [1,2,3] + 4
d. last [1,2,3] + 4
e. all of the above
D) Which of the following expressions does not have a type error?
a. head [1,2,3] ++ [4]
b. tail [1,2,3] ++ 4
c. init [1,2,3] + 4
d. last [1,2,3] ++ 4
e. none of the above
E) Which of the following expressions has the type [String]
a. [tail $ head ["Hello"]]
b. tail $ head [[],"Hello"]
c. head $ tail "Hello"
d. head $ tail ["Hello"]
e. tail [head $ tail "Hello"]
F) Which of the following expressions result in a runtime error?
a. head (tail [1..1000000])
b. tail (head [[],[1]])
c. last (init [1..1000])
d. init (last [[],[1]])
e. tail (head [[1],[]])
G) What is the full Haskell type for the lkp function below?
lkp _ [] = Nothing
lkp x ((y,z):ys) | x == y = Just z
| otherwise = lkp x ys
a. Eq a => a -> [(a, a)] -> Maybe a
b. Ord a => a -> [(a, b)] -> Maybe b
c. (Eq a, Ord a) => a -> [(a, b)] -> Maybe b
d. Eq a => a -> [(a, b)] -> Maybe b
e. a -> [(a, b)] -> Maybe b
H) In order to make Exp an proper instance of Num, what extra variants need to be added to the datatype?
data Exp = Nmb Int -- number
| Var String -- variable
| Add Exp Exp -- add two Exp
| Sub Exp Exp -- subtract second Exp from first
| Sgn Exp -- signum of Exp
a. Mul Exp Exp | Dvd Exp Exp
b. Neg Exp | Mul Exp Exp | Abs Exp
c. Abs Exp | Neg Exp
d. Neg Exp | Dvd Exp Exp | Def String Exp Exp
e. none of the above
I) What is the full Haskell type for the mlkp function below?
mlkp _ [] = Nothing
mlkp x ((y,z):ys) | x == y = Just z
| otherwise = mlkp x ys
a. (Monad m, Eq t) => t -> [(s,t)] -> m t
b. (Monad t, Eq s) => t -> [(s,t)] -> m t
c. (Monad m, Eq s) => s -> [(s,t)] -> m t
d. Monad m => t -> [(s,t)] -> m t
e. (Monad t, Ord s) => t -> [(s,t)] -> m t
J) Which reduction step in the sequence below is not in lazy reduction order?
take 3 (from 42)
=1= take 3 (42:from (42+1))
=2= 42 : take (3-1) (from (42+1))
=3= 42 : take 2 (from (42+1))
=4= 42 : take 2 (from 43)
=5= 42 : take 2 (43:from (43+1))
=6= 42 : 43 : take (2-1) (from (43+1))
=7= 42 : 43 : take 1 (from (43+1))
=8= 42 : 43 : take 1 ((43 + 1) : from (43+1))
a. =1=
b. =3=
c. =4=
d. =7=
e. =8=
H) Under which forms of evaluation will the following expression produce a concrete list? take 4 threes where threes = 3:threes
a. strict only
b. lazy only
c. neither lazy nor strict
d. both lazy and strict
e. none of the above
I) Under which forms of evaluation will the following expression return some form of value, and what will that value look like? drop 4 threes where threes = 3:threes
a.lazy, result is threes
b. lazy only, result is [3,3,3,..,3]
c. neither lazy nor strict, result is undefined
d. strict only, result is[3,3,3,..,3]
e. both lazy and strict, result is three
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
