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 NAA17958 for caml-redistribution; Mon, 31 Aug 1998 13:56:13 +0200 (MET DST) 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 TAA29819 for ; Sat, 29 Aug 1998 19:53:01 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.12]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id TAA26697 for ; Sat, 29 Aug 1998 19:53:00 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.8.8/jtpda-5.1) with ESMTP id TAA04354 ; Sat, 29 Aug 1998 19:52:58 +0200 (MET DST) Received: from drakkar.ens.fr (drakkar [129.199.129.5]) by clipper.ens.fr (8.8.7/jb-1.1) id TAA28076 ; Sat, 29 Aug 1998 19:52:57 +0200 (MET DST) Received: from (vouillon@localhost) by drakkar.ens.fr (8.9.0/jb-1.1) Message-ID: <19980829195252.21273@drakkar.ens.fr> Date: Sat, 29 Aug 1998 19:52:52 +0200 From: Jerome Vouillon To: Vladimir Vyskocil Cc: caml-list@pauillac.inria.fr Subject: Re: OCaml 2.0 References: <35E4193B.30969200@math.unice.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.88 In-Reply-To: <35E4193B.30969200@math.unice.fr>; from Vladimir Vyskocil on Wed, Aug 26, 1998 at 04:18:35PM +0200 Sender: weis Bonjour, On Wed, Aug 26, 1998 at 04:18:35PM +0200, Vladimir Vyskocil wrote: > - Nous avons des classes marquees closed qui posent probleme avec > Ocaml2.0, l'explication donnee > dans le fichier README de ocaml1to2 : > < c) from the > self type to a known closed class type c >> > n'est pas tres parlante pour nous, pourriez vous donner un exemple > simple ? Il y a un exemple dans le manuel, dans l'introduction aux objets (http://caml.inria.fr/ocaml/htmlman/node3.html, section "Using coercions"). Les exemples donnes a la fin de ce message doivent egalement pouvoir vous aider. > - Dans l'exemple suivant : > > class a = > object (self) > method call_pipo x = x#pipo self > end > ;; > Some type variables are unbound in this type: > class a : object ('a) method call_pipo : < pipo : 'a -> 'b; .. > -> 'b > end > The method call_pipo has type > < pipo : < call_pipo : 'a; .. > -> 'b; .. > -> 'b as 'a > where 'c is unbound > > Le type 'c n'apparait pas dans la signature de la classe, a quoi > correspond t'il ? Le type 'c represente en fait l'un des '..'. Vous devez preciser le type de la method call_pipo afin que les types objets ouverts soient instancies, ou bien soient lies par des parametres de la classe. Par exemple : class ['a] a = object (self) method call_pipo (x : 'a) = x#pipo self end;; > - Dans l'exemple suivant : > > class a = > object (self) > method call_pipo (x:b) = x#pipo self > end > and b a = > object > method pipo (x:a):a = x > end;; > This expression has type < call_pipo : b -> 'a; .. > > but is here used with type 'b > Self type cannot escape its class > > pourriez vous expliquer ce message d'erreur et donner une maniere de > re-ecrire cela ? La "row variable" ('..') du type de self doit pouvoir etre generalise une fois que la classe a est typee, afin que le type reste extensible. Pour cela, il ne faut pas qu'elle s'echappe de la classe. Par consequent, le type de self ne peut etre unifie avec une partie du type de b, dont la portee est aussi bien la classe a que la classe b. Il y a plusieurs facons de contourner ce probleme. La premiere est de masquer la row variable par une coercion. Une difficulte est que l'on voudrait faire une coercion vers le type a, ce qui n'est pas possible car ce type n'est pas completement defini a cet endroit. Par consequent, il faut definir explicitement le type de la coercion, en utilisant par exemple un type de classe : class type a0 = object method call_pipo : b0 -> a0 end and b0 = object method pipo : a0 -> a0 end;; class a = object (self) method call_pipo (x:b) = x#pipo (self : #a0 :> a0) end and b a = object method pipo (x:a):a = x end;; Une autre solution est de supprimer la recursion entre les classes a et b en donnant un type plus general a la classe b : class ['a] b a = object method pipo (x:'a) = x end class a = object (self) method call_pipo (x : 'a b) = x#pipo self end -- Jerome