From: Michael Wohlwend <micha-1@fantasymail.de>
To: caml-list <caml-list@inria.fr>
Subject: object question
Date: Wed, 14 Sep 2005 10:00:50 +0200 [thread overview]
Message-ID: <200509141000.50364.micha-1@fantasymail.de> (raw)
Hi,
I want to make some chained object and an "apply" function on this chain.
it might look as this (the functions don't make sense...yet :)
-----------------------------------------------
class type tst = object
method next: tst
method clr: unit
method apply: (tst -> unit) -> unit
end;;
let empty : tst = object(self)
method next = self
method clr = ()
method apply fkt = ()
end;;
class test : tst = object(self)
val mutable n = empty
method clr = ()
method next = n
method apply fkt = fkt (self :> tst) ; self#next#apply fkt (* Line 17 *)
end;;
let a = new test in
a#apply (fun o -> o#clr)
----------------------------------------------------
first question, why do I have to cast self to tst in Line 17? The class test
is defined to be of type tst, so self should allready be of type tst. But it
works only with the cast.
The other question, does this "apply" function use up the stack? Would it be
better to define a tail-recursive apply outside the class?
cheers
Michael
next reply other threads:[~2005-09-14 8:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-14 8:00 Michael Wohlwend [this message]
2005-09-14 12:01 ` [Caml-list] " Jacques GARRIGUE
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=200509141000.50364.micha-1@fantasymail.de \
--to=micha-1@fantasymail.de \
--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