0
votes

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" *)
1
Double check your example. Your code misses one closing parenthese. And the fixed code returns "Yes". - camlspotter
Thanks, It was a very silly mistake. - zeronone

1 Answers

2
votes

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"