From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA12683 for caml-red; Mon, 25 Dec 2000 23:09:54 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA08992 for ; Mon, 25 Dec 2000 23:09:42 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eBPM9fP27188; Mon, 25 Dec 2000 23:09:41 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA11293; Mon, 25 Dec 2000 23:09:41 +0100 (MET) From: Pierre Weis Message-Id: <200012252209.XAA11293@pauillac.inria.fr> Subject: Re: Ref polymorphism restriction In-Reply-To: from Ohad Rodeh at "Dec 25, 100 09:34:13 am" To: orodeh@cs.huji.ac.il (Ohad Rodeh) Date: Mon, 25 Dec 2000 23:09:40 +0100 (MET) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr > List, > The following program does not compile, with a > rather strange error message. > > module type SIG = > sig > val l : '_a list ref > val f : '_a -> unit > end Warning, there is a strange feature here that makes your '_a as type schemes paramters (generalized variables) and not type variables: Objective Caml version 3.00 # module type SIG = sig val l : '_a list ref val f : '_a -> unit end;; module type SIG = sig val l : 'a list ref val f : 'a -> unit end # In effect 'ident means a type scheme parameters. When we introduced type variables, we denote them by an _ prefix, that was not allowed in identifiers (as the first character) at that time. Now, identifiers are allowed to start with an _. Hence '_foo is a perfectly valid polymorphic type parameter! > module M : SIG = > struct > let l = ref [] > > let f a = l:= a::!l > end > > > Modules do not match: > sig val l : '_a list ref val f : '_a -> unit end > is not included in > SIG > Values do not match: > val l : '_a list ref > is not included in > val l : 'a list ref > > Note that the signature for list l IS '_a list ref. As mentioned above, no: it is 'a list ref. This explains the typechecker message. > I suppose this is due to the restriction on polymorphic references. > Is the OCaml restriction such that references may only be local to > a single module? Is there a different restriction? > > Ohad. > > ---------------------------------------------------------- > orodeh@cs.huji.ac.il > www.cs.huji.ac.il/~orodeh Anyway, your right: type variables ('_a types) should not escape the scope of a module. Merry Christmas, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/