Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1.2. What are the types of the following functions? (Note that this is question 3. in section 3.11 of the book.) Hint: checking them with
1.2. What are the types of the following functions? (Note that this is question 3. in section 3.11 of the book.) Hint: checking them with GHCi is a good idea. a. second xs = head (tail xs) In particular, 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? 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 'fe' has type 'b: if f:: a -> b' and `e: a', then 'fe::b b. swap (x,y) = (y,x) Why can 'x' and y correspond to different types? 1.2. What are the types of the following functions? (Note that this is question 3. in section 3.11 of the book.) Hint: checking them with GHCi is a good idea. a. second xs = head (tail xs) In particular, 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? 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 'fe' has type 'b: if f:: a -> b' and `e: a', then 'fe::b b. swap (x,y) = (y,x) Why can 'x' and y correspond to different types
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started