I have this very simple recursive function, to add a branch to a tree from a list of char.
type tree = Node of bool ref * (char * tree) list ref
let rec create_branch lc = function
[] -> Node(ref true, ref[])
| x :: l -> Node(ref false, ref [(x, (create_branch l))])
I would expect this to create a tree containing only one branch, which would have a bunch of "false" nodes with char transitions until the final node which would be true.
But I'm getting an error:
Error: This expression has type (char * (char list -> tree)) list ref but an expression was expected of type (char * tree) list ref Type char list -> tree is not compatible with type tree
I think I understand that this means that my recursive call seems to, for some reason, get passed as a reference to the actual function (hence the (char list -> tree)), instead of its return value, which would simply be a tree.
I'd like to know what I am doing wrong?