Answered step by step
Verified Expert Solution
Link Copied!

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)

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

What is meant by the term safety time?

Answered: 1 week ago