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 RAA15627 for caml-redistribution; Tue, 1 Jun 1999 17:14:56 +0200 (MET DST) 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 MAA02569 for ; Mon, 31 May 1999 12:57:05 +0200 (MET DST) 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 MAA26285 for ; Mon, 31 May 1999 12:57:04 +0200 (MET DST) 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 MAA25757 for ; Mon, 31 May 1999 12:57:04 +0200 (MET DST) 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 MAA18370 for ; Mon, 31 May 1999 12:57:01 +0200 (MET DST) Received: from ventoux.lip6.fr (530@localhost [127.0.0.1]) by ventoux.lip6.fr (8.8.7/jtpda-5.2) with ESMTP id MAA18022 for ; Mon, 31 May 1999 12:57:19 +0200 Message-Id: <199905311057.MAA18022@ventoux.lip6.fr> X-Mailer: exmh version 2.0.2 To: caml-list@inria.fr Subject: Re: OCAML parametric class coercion In-Reply-To: Your message of "Sun, 30 May 1999 22:24:35 +0200." <37519E82.7D14@cnam.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 31 May 1999 12:57:18 +0200 From: "Sylvain BOULM'E" Sender: weis In OCAML objects system, polymorphic methods are forbidden (for the decidability of the type inference) : only classes may be polymorphic. So, you have to bind types of methods to types parameters of classes (it's a kind of skolemistation). For instance : # class ['a] bidu1(dev) = object(self) method rate(untruc:'a) = untruc#essai end;; class ['a] bidu1 : 'b -> object constraint 'a = < essai : 'c; .. > method rate : 'a -> 'c end The system inferred the most general type, preventing an execution of "segmentation fault". Here, it adds a constraint ... But, you may also constraint by yourself this parameter (for a better readibility of code and inferred types, or semantic reasons about your classes) : # class ['a] bidu2(dev) = object(self) constraint 'a = 'c #truc method rate(untruc:'a) = untruc#essai end;; class ['a] bidu2 : 'b -> object constraint 'a = 'c #truc method rate : 'a -> int end # class ['a] bidu3(dev:'b) = object(self) constraint 'a = 'b #truc method rate(untruc:'a) = untruc#essai end;; class ['a] bidu3 : 'b -> object constraint 'a = 'b #truc method rate : 'a -> int end Yours, Sylvain.