From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: jhw@wetware.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] subtyping and inheritance (bug?)
Date: Tue, 25 Jun 2002 11:54:30 +0900 [thread overview]
Message-ID: <20020625115430E.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <BB7FA3E8-87E5-11D6-BC7A-000502DB38F5@wetware.com>
From: james woodyatt <jhw@wetware.com>
> Consider the following variation on a theme currently found in another
> thread on this list:
>
> > class tree =
> > object (_:'self)
> > val v = (None : string option)
> > val ch = ([] : 'self list) (* NOTE: 'a list is co-variant in 'a *)
> > method value_get = v
> > method value_set x = {< v = x >}
> > method children_get = ch
> > method children_set x = {< ch = x >}
> > end;;
> >
> > class colortree =
> > object
> > inherit tree
> > method color = "evergreen"
> > end;;
> >
> > ((new colortree) :> tree);; (* ERROR! *)
>
> Here, the compiler (ocaml-3.04) complains that objects of class subtree
> cannot be coerced to class tree.
Sure. The children_set method contains a contravariant occurence of 'self.
It cannot be compatible with its subclasses. You don't need to have
mutable data to have variance incompatibilities.
No bug, business as usual.
Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-06-25 2:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-25 2:46 james woodyatt
2002-06-25 2:54 ` Jacques Garrigue [this message]
2002-06-25 12:22 ` Eray Ozkural
2002-06-25 21:33 ` Brian Rogoff
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=20020625115430E.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=jhw@wetware.com \
/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;
as well as URLs for NNTP newsgroup(s).