Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Haskell Programming: Simply answer the question (Code) 2.[8 points] Define a function head repeats n x that returns True if the first n elements of
Haskell Programming: Simply answer the question (Code)
2.[8 points] Define a function head repeats n x that returns True if the first n elements of x equals the second n elements of x. E.g. head-repeats 2 13, 5, 3, 5, 7] should return True. If n s 0, return True. 3 [10 points] What's wrong with the following definition? Suggest a change to the definition that changes the arguments of f but preserves the spirit of the definition below. Also give the type of your new function f. 4. [15 points] Define a function swap_ends that takes a list and returns the same list but with the first and last elements swapped. E.g., swap_ends "hello" - "oellh" (remember, strings are lists of characters). Use function definition by cases to ensure that swap-ends [ ] = [ ] and swap-ends [ x] = [ x]. (Le., return empty and singleton lists as is). 5. 8 points] Here's a buggy definition for the general case of swap_ends. Briefly explain the nature of the bug and why we can't eliminate the bug if we rewrite the left hand side 2.[8 points] Define a function head repeats n x that returns True if the first n elements of x equals the second n elements of x. E.g. head-repeats 2 13, 5, 3, 5, 7] should return True. If n s 0, return True. 3 [10 points] What's wrong with the following definition? Suggest a change to the definition that changes the arguments of f but preserves the spirit of the definition below. Also give the type of your new function f. 4. [15 points] Define a function swap_ends that takes a list and returns the same list but with the first and last elements swapped. E.g., swap_ends "hello" - "oellh" (remember, strings are lists of characters). Use function definition by cases to ensure that swap-ends [ ] = [ ] and swap-ends [ x] = [ x]. (Le., return empty and singleton lists as is). 5. 8 points] Here's a buggy definition for the general case of swap_ends. Briefly explain the nature of the bug and why we can't eliminate the bug if we rewrite the left hand side
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