I need to break a list like [1;2;3;4;5]
into [[1;2]; [3;4]; [5]]
in OCaml.
I wrote the following function but it is giving me an error (Error: This expression has type 'a list but an expression was expected of type 'a The type variable 'a occurs inside 'a list)
let rec getNewList l =
match l with
[] -> failwith "empty list"
| [x] -> [x]
| x::(y::_ as t) -> [x;y] :: getNewList t;;
What am I missing? how can I fix it?