Functional Programming (H) - 5.09 - You are the type checker
1. What is the type of the
head
function?
head :: [a] -> a
head :: [a] -> Int
head :: a -> Int
head :: a -> a
2. What is the type of the
putStrLn
function?
putStrLn :: String -> IO ()
putStrLn :: String -> ()
putStrLn :: Show a => a -> IO ()
putStrLn :: Char -> IO ()
3. Given the following type declarations:
f :: T1 -> T2 g :: T2 -> T3
And given that the following expression typechecks:
v :: T1 v = h f g
What is the type of h?
h :: T3 -> T2 -> T1
h :: (T1 -> T2) -> (T2 -> T3) -> T1
h :: (T3 -> T2) -> (T2 -> T1) -> T3
h :: T1 -> T2 -> T3
4. What is the type of the following function:
\f -> f f
True
Bottom
It is not possible to type this expression correctly in Haskell
5. Complete the following type definition to define a binary tree with the values stored only in the leaf nodes:
data Tree a = Node __ __ | Leaf __
data Tree a = Node Tree Tree | Leaf
data Tree a = Node Leaf Leaf | Leaf (Tree a)
data Tree a = Node a a | Leaf
data Tree a = Node (Tree a) (Tree a) | Leaf a
6. What is the type of the following function (use a,b,c etc as type variables in order of occurence):
\x y -> y
\x y -> y :: a -> a -> a
\x y -> y :: a -> b -> b
\x y -> y :: a -> a -> b
\x y -> y :: a -> b -> c
7. Is the following expression correctly typed?
sq :: Int -> Float sq x = x*x
Yes
No
8. Is the following expression correctly typed?
join :: String -> [String] -> String join str strs = foldl (++) str strs
Yes
No
Submit Quiz