考虑以下小例子:
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
的具体类型使用我们构建的完整类进行更新。问题是:这个接口(interface)使类型检查器崩溃。我不明白为什么:
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 进行此操作。
最佳答案
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
看起来断言失败已修复。
关于recursion - 类型检查器断言在递归类型的类上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24915201/