Question: Ocaml Programing with obvious comments. 1. Write a function get_prefix_eq_int : int -> int list -> int list that returns a list consisting of only

Ocaml Programing with obvious comments.

1. Write a function get_prefix_eq_int : int -> int list -> int list that returns a list consisting of only the number that is its first argument; for as many as there are in the prefix to (start of) its second argument: get_prefix_eq_int 1 [1;1;3;4;1] = [1;1]. get_prefix_eq_int 2 [1;1;3;4;1] = []. get_prefix_eq_int 3 [3;3] = [3;3].

2. Write a function drop_prefix_eq_int : int -> int list -> int list that returns a list consisting of all elements in the second list with any occurrences of its first argument dropped at the start: drop_prefix_eq_int 1 [1;1;3;4;1] = [3;4;1]. drop_prefix_eq_int 2 [1;1;3;4;1] = [1;1;3;4;1]. drop_prefix_eq_int 3 [3;3] = [].

3. Write a function group_eq_int : int list -> int list list that returns a list of lists in which equal consecutive elements are grouped in a list. group_eq_int [1;1;3;4;1] = [[1;1];[3];[4];[1]]. group_eq_int [1;1;1;3;3;3;5;5;5;5] = [[1;1;1];[3;3;3];[5;5;5;5]].

4. Write a function group_eq : 'a list -> 'a list list that returns a list in which equal consecutive elements are grouped in a list. You might need some helper functions. group_eq [1;1;3;4;1] = [[1;1];[3];[4];[1]]. group_eq [1;1;1;3;3;3;5;5;5;5] = [[1;1;1];[3;3;3];[5;5;5;5]]. group_eq ["baby"; "shark"; "doo";"doo";"doo";"doo"] = [["baby"];["shark"];["doo";"doo";"doo";"doo"]].

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!