Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Homework 1 This homework assignment is out of 1 0 0 points ( the number of points for each exercise is indicated beside the exercise
Homework This homework assignment is out of points the number of points for each exercise is indicated beside the exercise You may submit your solution in the text window in iCollege, as a txt file, or in some other commonly used format, egpdfdocx, etc. Note that partial credit is available for explanations which convey the right ideas, even if they may not be totally correct or complete, and so showing or explaining your work or thought process why the answer is what you think it is is always a good idea. Consider the function second xs head tail xs a points What is the type of second? Note: that type has a formal meaning in Haskell, that is there is only one correct and very precise answer. b points Explain why second has the type that it has. That is why does chaining tail and head together or composing them in the function definition above give rise to the type that second has? Consider the functions swap and pair, defined respectively as swap xyyx pair x y xy a points What is the type of swap? b points What is the type of pair? c points Notice that, in the types of swap and pair, that x and y from the respective function definitions above correspond to two different polymorphic type variables. Why is this, ie why wouldnt they be the same? Consider the functions double and palindrome, defined respectively as double x x palindrome xs reverse xs xs a points What is the type of double? b points What is the type of palindrome? c points Notice that there are certain type class constraints present in both types of double and palindrome. What is the reason for this, in either case? points Consider the function twice f x f f x What constraints does twice place on the type that input function f can have? Hint: try seeing what happens when calling twice head in GHCi. points Notice that the list tail init, reverse has a type, however, if we try to construct tail init, reverse, head it will generate a type error. Why is this?
Homework
This homework assignment is out of points the number of points for each exercise is indicated beside the exercise You may submit your solution in the text window in iCollege, as a txt file, or in some other commonly used format, egpdfdocx, etc.
Note that partial credit is available for explanations which convey the right ideas, even if they may not be totally correct or complete, and so showing or explaining your work or thought process why the answer is what you think it is is always a good idea.
Consider the function
second xs head tail xs
a points What is the type of second? Note: that type has a formal meaning in Haskell,
that is there is only one correct and very precise answer.
b points Explain why second has the type that it has. That is why does chaining tail and head together or composing them in the function definition above give rise to the type that second has?
Consider the functions swap and pair, defined respectively as swap xyyx
pair x y xy
a points What is the type of swap?
b points What is the type of pair?
c points Notice that, in the types of swap and pair, that x and y from the respective function definitions above correspond to two different polymorphic type variables. Why is this, ie why wouldnt they be the same?
Consider the functions double and palindrome, defined respectively as double x x
palindrome xs reverse xs xs
a points What is the type of double?
b points What is the type of palindrome?
c points Notice that there are certain type class constraints present in both types of double and palindrome. What is the reason for this, in either case?
points Consider the function
twice f x f f x
What constraints does twice place on the type that input function f can have? Hint: try seeing
what happens when calling twice head in GHCi.
points Notice that the list tail init, reverse has a type, however, if we try to construct
tail init, reverse, head it will generate a type error. Why is this?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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