Reputation: 219
How to correct this error ?
type 'a drzewo = | Puste | Wezel of 'a * 'a drzewo * 'a drzewo
let rec inorder t =
match t with
| Puste -> print_int (-1)
| Wezel (v, l, r) -> (inorder l; print_int v; inorder r)
let tree =
(1,
(Wezel (2, (Wezel (3, Puste, Puste)),
(Wezel (4, (Wezel (5, Puste, Puste)), Puste)))),
(Wezel (6, Puste, Puste)))
let _ = inorder tree
And the log of error:
let _ = inorder tree;; Error: This expression has type int * int drzewo * int drzewo but an expression was expected of type int drzewo
Upvotes: 0
Views: 74
Reputation: 25812
The problem is here
let tree =
(1,
(Wezel (2, (Wezel (3, Puste, Puste)),
(Wezel (4, (Wezel (5, Puste, Puste)), Puste)))),
(Wezel (6, Puste, Puste)))
You didn't add Wezel
in front.
It should be:
let tree =
Wezel (1,
(Wezel (2, (Wezel (3, Puste, Puste)),
(Wezel (4, (Wezel (5, Puste, Puste)), Puste)))),
(Wezel (6, Puste, Puste)))
Upvotes: 1
Reputation: 1749
Your error message is already very informative, just carefully re-read it again. The type of 'tree' is 'int * int drzewo * int drzewo' (a triple), but it must be 'int drzewo' (because inorder has type 'int drzewo -> unit').
So just correct it:
let tree = Wezel (1,
(Wezel (2, (Wezel (3, Puste, Puste)),
(Wezel (4, (Wezel (5, Puste, Puste)), Puste)))),
(Wezel (6, Puste, Puste)))
Upvotes: 0