Question: 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)

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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!