Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, we will generalize the function from the previous problem so that the user can specify which elements to take from a list

In this problem, we will generalize the function from the previous problem so that the user can specify which elements to "take" from a list and then use it to define the function in the previous problem and others like it as special cases.

Define the function everyNth : ('a list) -> int -> ('a list) that will take a list and a positive number i and produce a new list that has every element whose position in the given list is a multiple of i. Some example outputs for the function follow: # everyimage text in transcribedNth [1;2;3;4] 2;; - : int list = [2; 4] # everyNth [1;2;3;4] 1;; - : int list = [1; 2; 3; 4] # everyNth [1;2;3;4;5;6] 3;; - : int list = [3; 6] # everyNth [1;2;3;4;5;6] 7;; - : int list = [] # Use the function everyNth to define the function everyThird that takes the third element of each given list. Note that your solution must use everyNth, i.e. it is not okay to define everyThird from first principles. In case there is any doubt, the behavior expected from the function is of the following kind: # everyThird [1; 2; 3; 4; 5];; - : int list = [3] # everyThird [1; 2; 3; 4; 5; 6];; - : int list = [3; 6] # everyThird [];; - : 'a list = [] # Important: Note again that we need you to define a function with exactly the name and type indicated above.

In this problem, we will generalize the function from the previous problem so that the user can specify which elements to "take" from a list and then use it to define the function in the previous problem and others like it as special cases. Define the function cveryth : ('a Listi -> int -> Ila 1.st) that will take a list and a positive nurnber i and produce a new list that has every element whose position in the given list is a multiple of i. Some example outputs for the function follow: #everybct 112;3,41 2!! - int. 11st- 2; 41 everyneba 11,2,371] 11 - at list = 1; 2; 3; 41 severynob 11;2;3;1,5,6) 377 - ! dat List [3; 6) everyth 11;2;3;4;5;6. 777 - ! iat list - 1 Use the function everyth to define the function every Third that takes the third element of each given list. Note that your solution must use everyth, i.e. it is not okay to define every Third from first principles. In case there is any doubt, the behavior expected from the function is of the following kind: + every bind 1; 2; 3; 4; 51:: -:int 1lt - (3) + every bird 1; 2; 3; 4; 5; 6111 - int. 11 - (3; 6) every bird 117 - a list = 0) In this problem, we will generalize the function from the previous problem so that the user can specify which elements to "take" from a list and then use it to define the function in the previous problem and others like it as special cases. Define the function cveryth : ('a Listi -> int -> Ila 1.st) that will take a list and a positive nurnber i and produce a new list that has every element whose position in the given list is a multiple of i. Some example outputs for the function follow: #everybct 112;3,41 2!! - int. 11st- 2; 41 everyneba 11,2,371] 11 - at list = 1; 2; 3; 41 severynob 11;2;3;1,5,6) 377 - ! dat List [3; 6) everyth 11;2;3;4;5;6. 777 - ! iat list - 1 Use the function everyth to define the function every Third that takes the third element of each given list. Note that your solution must use everyth, i.e. it is not okay to define every Third from first principles. In case there is any doubt, the behavior expected from the function is of the following kind: + every bind 1; 2; 3; 4; 51:: -:int 1lt - (3) + every bird 1; 2; 3; 4; 5; 6111 - int. 11 - (3; 6) every bird 117 - a list = 0)

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

Step: 3

blur-text-image

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

What do you look for when finding new friends?

Answered: 1 week ago

Question

Over the past

Answered: 1 week ago