I recently started learning ocaml and am having trouble figuring out a problem.
Goal:
Given a list of integers and a function, sort the integers into equivalence classes based on the given function as lists inside another list. The order of the equivalence lists must be the same as the order given in the original list.
Update: I have decided to try and get it working without library function.
This is my code so far. It compiles but does not run. Any help with syntax would be appreciated.
let buckets f lst =
let rec helpfunction f lst newlist =
match lst with
| [] ->newlist
| h::t -> match newlist with
| [] -> helpfunction f lst [h]@newlist
| [a]::_ -> if f h a
then helpfunction f t [a::h]@newlist
else helpfunction f t ([a]::[h]@mylist
IMPORTANT: this is a homework question, so I am not looking for the code pasted for me. Im trying to logic through it on my home with a bit of help with the overall thought-process and syntax. Once I get it working I would to work on making it more efficient