I have defined a type and a function:
type element = ...
let merge (x0: element) (x1: element): element * bool = ...
The second part of the return of merge represents if x0 and x1 are merge-able. If so, the first part of the return is the result of merging, otherwise the first part could be ignored.
Then I would like to realize a function restructure: element list -> element list which keeps merging as long as any 2 elements of the list are merge-able (we replace the 2 elements by the result of their merging of couse) the order of merging is not important.
I guess it must be a recursive function, and a little bit complicated for me at this stage, could anyone help?
Thank you very much
Ok, I could post a solution but that’s neither fun nor very instructive for you :). Instead let me try to give a few hints and if you’re still stucked I’ll try to help more.
mergefunction should returnoption(element), which is a classical way to return optional results of functions.restructureI suggest you start with a functionmerge_into(res : element, elts : element list)which will try to mergeeltsintores. That should, hopefully, be easier thanrestructure.restructureusingmerge_into?Don’t hesitate to let me know if you still have problems… happy coding! 🙂