4

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 class c can have elements of type bar which may in turn (somehow) reference to class c's complete representation. So by inheriting from class c, the concrete type for 'r gets updated with the complete class we have constructed.

The problem is: This interface crashes the typechecker. And I don't see 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 on why this is problematic, or how this bahaves with different versions of OCaml are very much appreciated.

choeger
  • 3,562
  • 20
  • 33
  • 1
    cool, indeed any failed assertion in ocaml compiler is a bug and should be reported. But do not forget to search a bugtracker, before you report – ivg Jul 23 '14 at 17:09
  • Bug is reported. Would be even cooler, if it was an error on my part ;). – choeger Jul 23 '14 at 18:01
  • Ticket - http://caml.inria.fr/mantis/view.php?id=6496 – nlucaroni Jul 23 '14 at 18:03
  • @choeger, notwithstanding whether or not your code is buggy, failed assertion indicates that something impossible has happened. I've seen a similar error in ocaml 4.00, though it wasn't exactly that. It was fixed in a next release. – ivg Jul 23 '14 at 19:05

1 Answers1

0
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

Looks like the assertion failure was fixed.

Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42