caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Confused: The example on page 48 where (self :> c) does not work
@ 2001-05-31 19:07 Sarino Suon
  2001-06-05 13:06 ` Didier Remy
  0 siblings, 1 reply; 2+ messages in thread
From: Sarino Suon @ 2001-05-31 19:07 UTC (permalink / raw)
  To: caml-list

Hi, all.

First, let me say that Ocaml is a wonderful language. Its typing
mechanism, though elaborate, appears to be robust, no matter how complex
by data structures become.

There's one problem that defies my understanding, though, and I hope
someone can help. 

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, 
in particular
these two lines of the following paragraph: "On the other hand, in
expression (self :> c) the type of self and the domain of the coercion
above must be unified. That is, the type of the method m in
self (ie. c) is also the type of self. So, the type of self is
c.

It seems, at first blush, that the problem hinges on the special idea of
self-ness. But it seems more involved than this. Can someone help me?

Thank you.

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Confused: The example on page 48 where (self :> c) does not work
  2001-05-31 19:07 [Caml-list] Confused: The example on page 48 where (self :> c) does not work Sarino Suon
@ 2001-06-05 13:06 ` Didier Remy
  0 siblings, 0 replies; 2+ messages in thread
From: Didier Remy @ 2001-06-05 13:06 UTC (permalink / raw)
  To: Sarino Suon; +Cc: caml-list

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);;

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-06-06 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-31 19:07 [Caml-list] Confused: The example on page 48 where (self :> c) does not work Sarino Suon
2001-06-05 13:06 ` Didier Remy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).