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 RAA06176 for caml-redistribution; Tue, 19 Jan 1999 17:55:01 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA20437 for ; Mon, 18 Jan 1999 21:37:22 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id VAA13193; Mon, 18 Jan 1999 21:37:20 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id VAA04696; Mon, 18 Jan 1999 21:37:20 +0100 (MET) From: Markus Mottl Message-Id: <199901182037.VAA04696@miss.wu-wien.ac.at> Subject: Re: Problem binding type parameters in modules + subtyping and inheritance To: Jerome.Vouillon@inria.fr (Jerome Vouillon) Date: Mon, 18 Jan 1999 21:37:20 +0100 (MET) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <19990118201616.45587@pauillac.inria.fr> from "Jerome Vouillon" at Jan 18, 99 08:16:16 pm X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis Hello, > 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;; Would certainly also work. But I guess it is better to stay with the functor - modules parameterized with a new value are not so common as function invocations. Thus, I won't have to change this much code porting Okasaki's sources. > ----------------------------------------------------------- > 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 *) Unfortunately, it's the binary methods I need... > 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 *) That's the problem: Actually the only method I would need is "compare" ;-) Regards, Markus -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl