I have been trying one of the problems on 99 ocaml problems where you have to a have a list of all consecutive numbers in a list such as [2;3;4;4;5;6;6;6] -> [[2];[3];[4;4];[5];[6;6;6]]
let rec tail = function
| [] -> []
| [x] -> [x]
| x::xs -> tail xs;;
let pack lst =
let rec aux current acc = function
| [] -> current
| [x] -> if ((tail acc)=x) then ((x::acc)::current) else ([x]::current)
| x::y::xs -> if (x=y) then aux (current) (x::acc) (y::xs) else aux (acc::current) ([]) (y::xs)
in
aux [] [] lst;;
When i run this i get the error
Error: This expression has type 'a list
but an expression was expected of type 'a list list
The type variable 'a occurs inside 'a list
I was wondering what the problem is? Thanks for any help it will be greatly valued
(tail acc)=x
seems to be the culprit – Bergi