【发布时间】:2017-10-04 23:34:25
【问题描述】:
由于某种原因,我收到错误消息,声称 distribute((AndC t),p) 是 cnf 而不是 cnf list... 除了 cnf list 是 cnf 的类型。为什么 OCaml 不承认这最终会提供一个列表?
问题点在第 11-12 行。
type cnf
= AtomC of signed_atom
| AndC of cnf list
| OrC of cnf * cnf
let rec distribute : cnf * cnf -> cnf =
let rec aux = function
| AndC [], _
| _, AndC [] -> AndC []
| AndC (h::t), p -> AndC( distribute(h,p) :: distribute((AndC t),p) )
| p, AndC (h::t) -> AndC( distribute(p,h) :: distribute(p,(AndC t)) )
| p, q -> OrC(p, q)
in aux
【问题讨论】:
标签: recursion types ocaml algebraic-data-types