Reputation: 3041
I am new to OCaml. I am trying to look for a way to check the equality of constructor types (union types ?) in the pattern matching.
type team = BRAZIL | KOREA;; type tourn = LEAF of team | NODE of tourn * tourn ;; let iter t d = match t with NODE ( (LEAF k), (LEAF i) ) when k = d -> "Yes" | _ -> "No" ;; iter (NODE ( (LEAF KOREA), (LEAF BRAZIL) ) KOREA (* returns "No" *)
Upvotes: 0
Views: 200
Reputation: 2839
It works OK, but you test it wrong. If you look again in last line you will see that )
is missing.
# iter (NODE (LEAF KOREA, LEAF BRAZIL)) KOREA ;;
- : string = "Yes"
Upvotes: 2