From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA17912; Fri, 8 Feb 2002 02:33:28 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 CAA17464 for ; Fri, 8 Feb 2002 02:33:27 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g181XQv10713 for ; Fri, 8 Feb 2002 02:33:26 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA24712; Fri, 8 Feb 2002 10:33:18 +0900 (JST) To: markus@oefai.at Cc: frisch@clipper.ens.fr, caml-list@inria.fr Subject: Re: [Caml-list] Type variables (was: Odd Type Checking Problem) In-Reply-To: <20020207122525.GB22578@fichte.ai.univie.ac.at> References: <20020207122525.GB22578@fichte.ai.univie.ac.at> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020208103318P.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 08 Feb 2002 10:33:18 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Markus Mottl > On Thu, 07 Feb 2002, Alain Frisch wrote: > > Actually, I feel myself somewhat confused with implicit introduction and > > scoping of type variables. > > > > These one are refused: > > > > let f (x : 'a) = let module M = struct exception X of 'a end in ();; > > let f (x : 'a) = let module M = struct type t = 'a end in ();; > [snip] > > Is there a way to use a type variable such as the 'a above to define > > types in a local structure ? > > This issue has already popped up in the past. See, for example: > > http://caml.inria.fr/archives/200107/msg00223.html > > There is unfortunately no way (yet) to use type variables in the way > shown above. When there is a type variable in a type definition, the type > checker will look for a binding at the level of the type definition, > not any further (I hope this explanation comes close to what is really > happening). This is actually worse than that: the interaction between let module and type annotations in an expression is not well defined. Here is an example of that: # let f x (y : 'a) = (x : 'a);; val f : 'a -> 'a -> 'a = # let f x (y : 'a) = let module M = struct let z = 1 end in (x : 'a);; val f : 'a -> 'b -> 'a = Basically, what happens is that you forget all type annotations everytime you type anything inside a module. So what you believed to be a related use of 'a is actually a completely different type variable. This should probably be corrected: at least restore original binding of type variables when exiting a module. > Are there any plans to lift this restriction? This would e.g. allow using > polymorphic types in functor arguments that expect monomorphic instances, > because the free variable could be bound in an outer scope. For instance, > one could create "polymorphic" sets of elements with the already existing > Set-implementation. Interesting point. It looks like it could work locally. Notice however that you wouldn't be able to to return such a set from the scope of the let module. So basically you've not not earned a lot: just the capacity to hide the fact you're calling a functor inside your function. Currently you would have to make your function into a functor. Jacques Garrigue ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr