【问题标题】:Typechecker assertion failed on recursively-typed class类型检查器断言在递归类型的类上失败
【发布时间】: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


【解决方案1】:
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

看来断言失败已修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 2018-03-11
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多