Question: Part A Write a function in Ocaml flatten : 'a list list -> 'a list that flattens a list. For example, flatten [[1;2];[3;4]] = [1;2;3;4].

Part A

Write a function in Ocaml

flatten : 'a list list -> 'a list 

that flattens a list. For example, flatten [[1;2];[3;4]] = [1;2;3;4].

In [ ]:

let rec flatten l = (* YOUR CODE HERE *) raise (Failure "Not implemented") 

In [ ]:

assert (flatten ([[1;2];[3;4]]) = [1;2;3;4])

Part B

Write a function in Ocaml

remove_stutter : 'a list -> 'a list 

that removes stuttering from the original list. For example, remove_stutter [1;2;2;3;1;1;1;4;4;2;2]= [1;2;3;1;4;2]. Option type may come in handy.

In [ ]:

let remove_stutter l = (* YOUR CODE HERE *) raise (Failure "Not implemented") 

In [ ]:

assert (remove_stutter [1;2;2;3;1;1;1;4;4;2;2] = [1; 2; 3; 1; 4; 2])

use Ocaml

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!