我是OCaml的新手。我试图找到一种方法来检查模式匹配中构造函数类型(联合类型?)的相等性。
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" *)
答案 0 :(得分:2)
它运行正常,但你测试错了。如果您在最后一行再次查看,则会看到)
丢失。
# iter (NODE (LEAF KOREA, LEAF BRAZIL)) KOREA ;;
- : string = "Yes"