Here are the various mistakes you made in your code:
(None, _) -> LEmpty
This is wrong, there is no reason for elem
to be an option type. In the LEmpty
case, simply use LEmpty
to define the children of the lazy tree returned.
| LCons(x, xs) -> toLBST_rec (xs()) add(x, tree)
You forgot parentheses around add(x, tree)
.
in toLBST_rec (listal, LEmpty);;
You defined toLBST_rec
to take two parameters, now you're passing it only one, of the wrong type (a pair of a list and a tree ,while the parameter expects only a list). You seem to be confused about the syntax of multi-parameter (currified) functions in OCaml. You should avoid (.. , ..)
in function declarations and calls, and define instead let rec add elem tree =
, etc.