From: Martin Sandin <om_sandin@yahoo.com>
To: caml-list@inria.fr
Subject: Re: class subtyping
Date: Fri, 17 Dec 2004 08:18:53 -0800 (PST) [thread overview]
Message-ID: <20041217161853.80122.qmail@web50910.mail.yahoo.com> (raw)
nakata keiko wrote:
> Why an instance of class a can not coerced into type
b?
I'll assume you mean the other way around :-)
> class a = object (self : 'a)
> method f (x : 'a) = x#g
> method g = 0
> end
>
> class b = object
> inherit a
> method h = 1
> end
>
> let x = ((new b) :> a)
Afaik the self type refers to actual type of the
object, eg in object
of class b it refers to type b. Thus, the method f of
class b
requires an object of type b as a parameter, and type
b implies
having a method h. Objects of class a don't have this
method,
and so b#f can't accept all the arguments a#f can.
Google for co/contra variance for discussions of these
issues.
The below class avoids the problem:
class a = object
method f (x : a) = x#g
method g = 0
end
/Martin
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
next reply other threads:[~2004-12-17 16:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-17 16:18 Martin Sandin [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-12-17 15:00 nakata keiko
2004-12-17 16:17 ` Martin Sandin
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=20041217161853.80122.qmail@web50910.mail.yahoo.com \
--to=om_sandin@yahoo.com \
--cc=caml-list@inria.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