From: Didier Remy <remy@morgon.inria.fr>
To: Anton Moscal <msk@post.tepkom.ru>
Cc: caml-list@inria.fr
Subject: Re: Objects as sums
Date: Thu, 26 Nov 1998 16:58:42 +0100 [thread overview]
Message-ID: <19981126165842.07547@morgon.inria.fr> (raw)
In-Reply-To: <Pine.LNX.4.03.9811251811020.1044-100000@post.tepkom.ru>; from Anton Moscal on Wed, Nov 25, 1998 at 06:17:35PM +0300
> class a = object (self)
> method b () = ((assert false): b)
> method c () = ((assert false): c)
> end
Here the type of method b is a (the type of objects of class a)
> and b = object (self)
> inherit a
> method b () = self
> end
The type of self is not the type a, since self may be an object ofa subclass
of a (imagine you are calling method b from a subclass of b). The system
tries to unify the type of self with a, and then fails.
One solution at this point is to write class b as follows:
class b = object (self)
inherit a
method b () = (self : #a :> a)
end;;
so that extra methods are hidden and self can be seem with type a.
However, it would have been better to define a as follows (which is probably
what you meant):
class a = object (self : 'a)
method b () = ((assert false): 'a)
method c () = ((assert false): 'a)
end;;
Here, the methods b and c return an object of the same type as their own
type. In particular, in a subclass, they will return an object of the type
of objects of the subclass...
Then, the rest of the example works unchanged.
class c = object (self)
inherit a
method c () = self
end;;
-Didier.
next prev parent reply other threads:[~1998-11-26 16:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-27 20:35 Local opening of modules John Prevost
1998-11-10 16:04 ` Anton Moscal
1998-11-10 21:22 ` John Prevost
1998-11-25 15:17 ` Objects as sums Anton Moscal
1998-11-26 15:58 ` Didier Remy [this message]
1998-11-28 10:46 ` Anton Moscal
1998-11-30 12:35 ` Jerome Vouillon
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=19981126165842.07547@morgon.inria.fr \
--to=remy@morgon.inria.fr \
--cc=Didier.Remy@inria.fr \
--cc=caml-list@inria.fr \
--cc=msk@post.tepkom.ru \
/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