English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Weird behavior with mutually recursive type definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-08-22 (18:17)
From: Francois Pottier <Francois.Pottier@i...>
Subject: Re: Weird behavior with mutually recursive type definitions

> Why is it so? Constraints are required for the object system, and if
> there are constraints you must expand abbreviations inside definitions
> to check them.  If recursion occurs before the abbreviation is
> generalized, this means that all occurences of an abbreviation in the
> same type definition will be unified, and have the same constraints.

I fail to see why type abbreviations should be monomorphic while
their declaration is being checked. Is this intended to make the
type system safe, or to guarantee the typechecker's termination?

By the way, I find O'Caml's error messages on this topic rather
strange. If I try:

  type 'a t = ('a -> 'a) u
  and 'a u = ('a -> 'a) t

then I obtain

  This type ('a -> 'a) -> 'a -> 'a should be an instance of type 'a

which corresponds to the problem discussed so far. This seems to
indicate that t and u are understood as mutually recursive type
abbreviations. However, if I try:

  type t = u and u = t

then O'Caml answers

  A type variable is unbound in this type declaration

which surprises me. I would rather expect to be warned about
cyclic type abbreviations.

François Pottier