简体   繁体   中英

Type Constructor equality in OCaml

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" *)

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM