Typechecker断言在递归类型的类上失败了

时间:2014-07-23 15:49:42

标签: recursion polymorphism ocaml assertion typechecking

考虑以下小例子:

type 'r foo_t = <get : 'r bar option ; set : 'r bar option -> 'r; ..> as 'r 

and 'r bar
constraint 'r = 'r foo_t

class c : object('r)
  constraint 'r = 'r foo_t
  method get : 'r bar option
  method set : 'r bar option -> 'r
end

这里的概念是,类c可以包含bar类型的元素,这些元素可以反过来(以某种方式)引用类c完整表示。因此,通过继承自类c'r的具体类型将使用我们构建的完整类进行更新。

问题是:这个界面崩溃了类型检查器。我不明白为什么:

choeger@daishi /tmp % ocamlc -v                                   
The OCaml compiler, version 4.00.1
Standard library directory: /usr/lib64/ocaml
choeger@daishi /tmp % ocamlc -c -annot -o test.cmi test.mli 
Fatal error: exception Assert_failure("typing/ctype.ml", 246, 27)

所以任何有关为什么会出现问题的提示,或者对于不同版本的OCaml如何使用它们都非常感激。

1 个答案:

答案 0 :(得分:0)

ocaml
    OCaml version 4.02.3

# type 'r foo_t = <get : 'r bar option ; set : 'r bar option -> 'r; ..> as 'r 
  and 'r bar constraint 'r = 'r foo_t;;

Error: The definition of bar contains a cycle:
   'a foo_t as 'a

看起来断言失败是固定的。