From: Jerome Vouillon <vouillon@clipper.ens.fr>
To: Vladimir Vyskocil <vyskocil@math.unice.fr>
Cc: caml-list@pauillac.inria.fr
Subject: Re: OCaml 2.0
Date: Sat, 29 Aug 1998 19:52:52 +0200 [thread overview]
Message-ID: <19980829195252.21273@drakkar.ens.fr> (raw)
In-Reply-To: <35E4193B.30969200@math.unice.fr>; from Vladimir Vyskocil on Wed, Aug 26, 1998 at 04:18:35PM +0200
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 :
> <<It usually suffices to introduce coercions (self :> 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
next prev parent reply other threads:[~1998-08-31 11:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-26 14:18 Vladimir Vyskocil
1998-08-29 17:52 ` Jerome Vouillon [this message]
1998-08-30 10:38 ` boos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19980829195252.21273@drakkar.ens.fr \
--to=vouillon@clipper.ens.fr \
--cc=caml-list@pauillac.inria.fr \
--cc=vyskocil@math.unice.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox