Question: 4. Consider the function second xs = head (tail xs) What is its type? Explain why second has the type that it has, i.e., tail
4.
Consider the function
second xs = head (tail xs)
What is its type?
Explain why "second" has the type that it has, i.e., "tail :: [a] -> [a]", hence "xs :: [a]", and "head :: [a] -> a", etc. Why does chaining them together like in the definition of "second" give us the type that it has?
Note: this will use the fact that if "f" is a function that maps arguments of type "a" to results of type "b", and "e" is an expression of type "a", then the application "f e" has type "b", that is:
if "f :: a -> b" and "e :: a" then "f e :: b"
5.
Consider the function
swap (x,y) = (y,x)
What is its type?
Why can "x" and "y" correspond to different types in general?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
