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 RAA02571 for caml-redistribution; Tue, 19 Jan 1999 17:54:37 +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 UAA14093 for ; Mon, 18 Jan 1999 20:16:19 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id UAA25202; Mon, 18 Jan 1999 20:16:15 +0100 (MET) Received: (from vouillon@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA16544; Mon, 18 Jan 1999 20:16:16 +0100 (MET) Message-ID: <19990118201616.45587@pauillac.inria.fr> Date: Mon, 18 Jan 1999 20:16:16 +0100 From: Jerome Vouillon To: Markus Mottl Cc: OCAML Subject: Re: Problem binding type parameters in modules + subtyping and inheritance References: <199901181459.PAA01741@ventoux.lip6.fr> <199901181707.SAA12530@miss.wu-wien.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.89.1 In-Reply-To: <199901181707.SAA12530@miss.wu-wien.ac.at>; from Markus Mottl on Mon, Jan 18, 1999 at 06:07:56PM +0100 Sender: weis Hello, > > To solve your problem, you may use functors: > > > > module type FOO1 = functor (M:sig type elt end) -> > > sig > > type foo > > val empty : foo > > end;; > > > > module Bar: FOO1 = functor (M:sig type elt end) -> > > struct > > type foo = M.elt list > > let empty = id [];; > > end;; Another solution is to turn "empty" into a function : module type FOO1 = sig type 'a foo val empty : unit -> 'a foo end;; module Bar : FOO1 = struct type 'a foo = 'a list Lazy.t let empty () = lazy [] end;; ----------------------------------------------------------- > There just has to be a single, innocent looking class with the > "'self"-type at the top of the inheritance hierarchie and it is impossible > to coerce any of its descendants to any ancestor in the same line. Actually, it is still possible to make the coercion when the type of self only occur in covariant position (in particular, only on the right sides of arrows) : class c = object (self) method m = self end;; class d = object (self) inherit c method n = 1 end;; let x = (new d :> c);; There is a difficulty with "binary methods", where self type occurs in contravariant position : class c = object (self : 'a) method x = 1 method compare (o : 'a) = self#x = o#x end;; class d = object inherit c method y = 1 end;; let x = (new d :> c);; (* Fails *) However, you can coerce to a common supertype of c and d which has no method "compare" : class type c' = object method x : int end;; let l = [(new c :> c'); (new d :> c')];; (* Succeeds *) -- Jérôme