From: Andrew Conway <arc@sequence.Stanford.EDU>
To: caml-list@pauillac.inria.fr
Subject: Closed Objects
Date: Thu, 12 Sep 1996 12:22:43 -0700 (PDT) [thread overview]
Message-ID: <199609121922.MAA19250@vegemite.Stanford.EDU> (raw)
Dear Caml Implementors,
I was wondering if you could give some comments upon the interactions
of classes returning self, type coercions, inheritance and closedness.
In particular, I do not understand the rules on closedness.
I was trying to make a "list like" class, and found the following
effects:
(* Base list class. Has no "head", but I am not interested about
storing data in it yet. This works in ocaml 1.00 and 1.01.
The "myself" method will usually be "self", but occasionally
(in some subclasses) it will refer to something else.
*)
class virtual runaround () as self : 'a =
virtual null : bool
virtual next : runaround
virtual myself : runaround
end;;
(* Add a method. This DOESN'T compile in ocaml 1.01, but
did compile in ocaml 1.00. The error message says that it
is closed, but not marked closed.
I don't want it to be closed. Is it impossible to return "self"
in a non-closed class?
*)
class virtual run2 () as self =
inherit runaround ()
method myself = (self :> runaround)
end;;
(* the sort of way things would be used (works without "myself") *)
class stop () as self =
inherit run2 ()
method null = true
method next = invalid_arg "stop"
method junk = 6
end;;
class go n as self =
inherit runaround ()
val storen = n
method null = false
method next = storen
method myself = (self :> runaround)
end;;
let s = new stop ();;
let ss = (s :> runaround) ;;
let g = new go ss;;
let gg = new go g;;
let rec laps x =
if x#null then 0 else 1 + laps x#next
;;
laps g;;
laps gg;;
next reply other threads:[~1996-09-13 7:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-09-12 19:22 Andrew Conway [this message]
1996-09-13 12:31 ` 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=199609121922.MAA19250@vegemite.Stanford.EDU \
--to=arc@sequence.stanford.edu \
--cc=caml-list@pauillac.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