[英]Type Constructor equality in OCaml
I am new to OCaml. 我是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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.