Chapter Questions
What are the types of the following values?[’a’,’b’,’c’]
(’a’,’b’,’c’)
[(False,’O’),(True,’1’)]
([False,True],[’0’,’1’])
Write down definitions that have the following types; it does not matter what the definitions actually do as long as they are type correct.bools :: [Bool]
nums :: [[Int]]
add :: Int -> Int -> Int -> Int
copy :: a -> (a,a)
apply :: (a -> b) -> a -> b
What are the types of the following functions?second xs = head (tail xs)
swap (x,y) = (y,x)
pair x y = (x,y)
double x = x*2
palindrome xs = reverse xs == xs
twice f x = f (f x)
Check your answers to the preceding three questions using GHCi.
Why is it not feasible in general for function types to be instances of the Eq class? When is it feasible? Hint: two functions of the same type are equal if they always return equal results for equal arguments.