【发布时间】:2014-09-14 21:58:53
【问题描述】:
考虑以下小例子:
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)
因此,非常感谢任何关于为什么这是有问题的提示,或者这个 bahaves 如何使用不同版本的 OCaml。
【问题讨论】:
-
酷,事实上,ocaml 编译器中任何失败的断言都是一个错误,应该报告。但不要忘记在报告之前搜索错误跟踪器
-
报错。如果这是我的错误,那就更酷了;)。
-
@choeger,不管你的代码是否有问题,失败的断言表明发生了不可能的事情。我在 ocaml 4.00 中看到过类似的错误,但并非完全如此。它已在下一个版本中修复。
标签: recursion polymorphism ocaml assertion typechecking