I am implementing this hoemwork functionality using Ocaml:
- Not allowed to use
Listmodule - the function has type
'a list list -> 'a list - the function return a list consisting of the lists in x concatenated together (just top level of lists is concatenated, unlike List.flatten)
- For example :
[[1,2,3],[45]] => [1,2,3,4,5]and[[[1,2,3],[4,5]],[[6,7]]] => [[1,2,3],[4,5],[6,7]]
I am not sure where to start, can anyone give me some suggestion? Thank you
I don’t see the difference between
List.flattenand your function.To answer to your question: as usual with lists, try to think about the base cases:
Wrap everything into a pattern match, cook it for few hours, and that’s done 🙂