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 TAA26937 for caml-redistribution; Mon, 18 Jan 1999 19:23:56 +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 PAA00959 for ; Mon, 18 Jan 1999 15:44:04 +0100 (MET) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id PAA06726 for ; Mon, 18 Jan 1999 15:44:03 +0100 (MET) Received: from spi.lip6.fr (monbazillac.lip6.fr [132.227.82.65]) by isis.lip6.fr (8.8.8/jtpda-5.2.9.1+lip6) with ESMTP id PAA23641 ; Mon, 18 Jan 1999 15:42:43 +0100 (MET) Received: from ventoux.lip6.fr (root@ventoux.lip6.fr [132.227.83.34]) by spi.lip6.fr (8.8.6/jtpda-5.2) with ESMTP id PAA12300 ; Mon, 18 Jan 1999 15:42:41 +0100 (MET) Received: from ventoux.lip6.fr (boulme@localhost [127.0.0.1]) by ventoux.lip6.fr (8.8.8/jtpda-5.2) with ESMTP id PAA01741 ; Mon, 18 Jan 1999 15:59:05 +0100 Message-Id: <199901181459.PAA01741@ventoux.lip6.fr> X-Mailer: exmh version 1.6.9 05/05/96 To: Markus Mottl Cc: caml-list@inria.fr Subject: Re: Problem binding type parameters in modules In-reply-to: Your message of "Sat, 16 Jan 1999 13:21:35 +0100." <199901161221.NAA00134@miss.wu-wien.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 18 Jan 1999 15:59:05 +0100 From: "Sylvain BOULM'E" Sender: weis Hello !! The problem you mentionned, comes from the type rule of O'Caml : "there is a the type generalization ONLY on values..." For exemple (as an application is not a value), In the environnement : module type FOO1 = sig type 'a foo val empty : 'a foo end;; let id x = x;; The following definition fails to typecheck : module Bar : FOO1 = struct type 'a foo = 'a list let empty = id [];; end;; This restritriction has been made to deals with "polymorphic references". Indeed, without this restriction the following lines success to typecheck : let empty = ref [];; let push x = empty:=x::!empty;; (push 1);; (push true);; which shows that there is no typesystem any more. so in "let empty=ref []", empty has type '_a list ref where the "_" in the "'_a" means that "'_a" could be instanced only once. Actually, the restriction may seems a bit strong, but it seems difficult to decide if an expression should be polymorphic or not.... 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;; ----------------------------------------------------------- The main drawback about your propositions in "subtyping and inheritance - correction", is the semantic of methods becomes very hard to understand (because it depends on the context). It is already not easy to understand the difference between subtyping and polymorphism on objects, but actually you don't care, because it doesn't affect the behaviour of methods (you may only have difficulties to typecheck). Best regards. Sylvain