Hello,
I have an odd error when calling my function:
> let rec tfold (l: 'a -> 'b) (f: 'a -> 'b -> 'b -> 'b) (t: 'a tree) : 'b =
> match t with
> | Leaf(x) -> x
> | Fork(x, a, b) -> f x (tfold l f a) (tfold l f b)
let sum_tree_fold (t: int tree) : int = tfold (fun a -> a) (fun x l r -> x + l + r) t
let t4 = Fork (7, Fork (5, Leaf 1, Leaf 2), Fork (6, Leaf 3, Leaf 4))
Error: This expression has type int tree/1919
but an expression was expected of type int tree/1979
This happens when you redefine a datatype at the toplevel, but still have some bindings around which are defined in terms of the old version. When the old type and the new type clash, you will get an error like this where the type constructor names are the same.
An example toplevel session to demonstrate:
# type fnord = A | B;;
type fnord = A | B
# let x = A;;
val x : fnord = A
# type fnord = A | B;;
type fnord = A | B
# let test = function A -> "a" | B -> "b";;
val test : fnord -> string = <fun>
# test x;;
Characters 5-6:
test x;;
^
Error: This expression has type fnord/1290
but an expression was expected of type fnord/1294
#
Note that this will quite often happen when you load and then reload source files, say with #use.
If you had this error in the toplevel, simply restart the session, and try to avoid redefining the same type twice. If you got this error outside of the toplevel, it would help to have the whole code, but general idea is that you should try to avoid collision of type names (or paths).