Question
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: # everyNth [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
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