English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Confused: The example on page 48 where (self :> c) does not work
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-06-06 (20:52)
From: Didier Remy <remy@m...>
Subject: Re: [Caml-list] Confused: The example on page 48 where (self :> c) does not work
Sarino Suon <doggreen@smoke.propagation.net> writes:

Dear Sarino,

> I'm trying to understand the example on page 48 of the Ocaml release 3.00
> documentation (PDF format). This was to show the case where omitting the
> domain of a coercion does not work. Here's the example:
> class virtual c = 
> 	object
> 		method virtual m:c
> 	end;;
> class c' = 
> 	object (self) inherit c
> 		method m = (self :> c)       (* !!! *)
> 		method m' = 1
> 	end;;
> I don't understand the explanation why the coercion would cause a problem, 

This was true in a previous version of the language.  The mecanism for
semi-implicit coercions (_ :> _) has been slightly changed in the current
version of the langage, so as to handle more common cases.  Unfortunately,
the manual has not been changed, acccordingly. (This has already be pointed
out to me, and it will be fixed in the next version.)

The new mechanism handle more common cases, but still does not
accept all of them. For instance, with

     class type c1 =  object ('a) method m : 'a end;;
     class type c2 =  object method m : c2 end;;
     class c = object method m = {< >} method n = 0 end;;

Class types c1 and c2 differ, but object type c1 and c2 are equal.
The following coercion is accepted: 

     (new c' :> c1);;

However, the following, although correct, is rejected

     (new c' :> c2);;

In this case, the explicit (_ : _ :> _) form should be used: 

     (new c' : c' :> c2);;

To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr