recursion - 类型检查器断言在递归类型的类上失败

标签 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 的具体类型使用我们构建的完整类进行更新。

问题是:这个接口(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/

相关文章:

linux - GODI安装问题

python - 递归函数不返回值

java - 数独的逻辑求解算法(Java)

Objective-C 类别

java - 如何防止接口(interface)出现冗余代码

OCaml:公开抽象类型的替代方法

module - 隐藏在 OCaml 中的外部和内部接口(interface)和信息

java - 递归方法 - 标尺刻度线

c - 为什么 'static int'在递归计算链表长度时给出不同的答案?

c# - 将多态列表合并为一个列表并获取派生类型