Typechecker statement failed for recursively typed class

Consider the following small example:

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

The concept here is that a class ccan have elements of a type barthat can in turn (somehow) refer to the full representation of the class c. Thus, inheriting from the class c, the concrete type for is 'rupdated with the full class that we created.

The problem is this: this interface issues a typechecker command. And I do not understand why:

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)

So any hints as to why this is problematic, or how bahaves with different versions of OCaml are really appreciated.

+4
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

, .

0

All Articles