From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
To: caml-list@inria.fr
Subject: Sharing inheritance ?
Date: Mon, 02 Nov 1998 10:32:08 +0100 [thread overview]
Message-ID: <363D7C18.FE3FB555@univ-savoie.fr> (raw)
I have a problem with the following situation:
---
class a (x : int) =
object
val mutable v = x
method get = v
method set x = v <- x
end
;;
class b x =
object (self)
inherit a x as super
method getb = self#get
method setb = self#set
method oldget = super#get
end
;;
class c x =
object (self)
inherit a x
method getc = self#get
method setc = self#set
end
;;
class d x =
object
inherit b x
inherit c x
end
;;
(* produces:
Warning: the following methods are overriden by the inherited class:
get set
Warning: this definition of an instance variable v hides a previously
defined instance variable of the same name
*)
let o = new d 2;;
o#setb 3;;
o#getc;; (* produces 3 *)
o#oldget;; (* produces 2 *)
---
I understand what is happening, but I would prefer is the default semantic was
two merge two values with the same name in an object (giving a type error if
their types can not unify).
Then one could have a syntactic sugar to change the name of some value:
class d x =
object
inherit b x
inherit c x with v -> v'
end
;;
To ask to rename the value v from b as v'. Together with the possibility to
bind a name to acces old method, this will allow a total flexibility (I can
always do what I want) which is not the case now.
---
Moreover, the follwing would become possible:
class d =
object
inherit b 0 with v -> v0 as b0
inherit b 1 with v -> v1 as b1
inherit b 2 with v -> v2 as b2
end
;;
Christophe Raffalli
Universite de Savoie
PS: do not forget to add "inherit" and "open ... in" for structure in
the next release, that will make some program simpler.
next reply other threads:[~1998-11-03 15:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-11-02 9:32 Christophe Raffalli [this message]
[not found] ` <363F3B0C.C2EACDBC@math.unice.fr>
1998-11-04 9:43 ` Christophe Raffalli
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=363D7C18.FE3FB555@univ-savoie.fr \
--to=christophe.raffalli@univ-savoie.fr \
--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