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])
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
