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
Type constraints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-08 (14:23)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Type constraints
From: Alain Frisch <Alain.Frisch@inria.fr>
> Damien Doligez wrote:
> > Hmmm...  Now I don't know whether it's safe or not, and I don't know
> > whether someone checked its safety before excluding it from the value
> > restriction code...
> With this extra line added to is_nonexpansive:
>    | Texp_letmodule (_,_,e) -> is_nonexpansive e
> we get:
> # let module M = struct let x = ref [] end in M.x;;
> - : 'a list ref = {contents = []}
> The non-generalizable status has been forgotten. What I'm not sure is 
> whether this is only an artefact of the internal representation of 
> levels to control generalization, or whether there are some deeper issues.

It's not really an artefact, just that there is no such thing as a
non-generalizable status: something that is not generalizable in some
context becomes generalizable in a larger context.
So you cannot rely on the generalizability obtained during the typing
of the module. Rather you must check whether the module
itself contains only non-expansive definitions. I.e. you cannot ignore
the definition of the module, as you are doing here.

Yet, modules are strange beasts for typing, so I wouldn't add the code
before thinking it through.

(Note that there is another way to handle non-generalizability,
without relying on a non-expansiveness predicate, raising the
non-generalizable level only when entering functions, and that might
solve the problem for free. Francois Pottier told me he was using
it. However it requires many small changes to type inference, and
doesn't mix well with the new "relaxed" value restriction.)

Jacques Garrigue