From: Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
To: caml-list@inria.fr
Subject: [Caml-list] Hiding public methods/friends methods
Date: Tue, 22 Jan 2002 18:26:21 +0100 [thread overview]
Message-ID: <20020122182621.B8021@cs.unibo.it> (raw)
Hi,
I would like to define a huge bunch of mutual recursive classes
with "friends methods". (The code is automatically generated, so
I don't mind very much an heavy coding style.)
Of course, I can use the trick of abstracting the output type
of all the friends methods in the signature of the module.
Because I have lots of friends methods, though, the resulting
.mli I get is quite confusing.
Another solution is creating "proxy" objects (see the code below).
But I fear the performance loss to be significant.
Which solution is best (not withstanding performances) and why?
(Or which is a much better solution I don't see ;-)
Thanks in advance,
C.S.C.
(* This is the interface I would like to have. *)
module type MT =
sig
class type ct = object method get_c' : ct' method m : int end
and ct' = object method get_c : ct method m' : int end
class c : int -> ct
class c' : int -> ct'
end
;;
module M : MT =
struct
(* This is the implementation: obj and obj' are the two public methods
* I want to hide.
*)
class _c (obj : int) =
object
method obj = obj
method get_c' = new _c' obj
method m = (new _c' obj)#obj'
end
and _c' obj =
object
method obj' = obj
method get_c = new _c obj
method m' = (new _c obj)#obj
end
(* Again the interface... *)
class type ct =
object
method get_c' : ct'
method m : int
end
and ct' =
object
method get_c : ct
method m' : int
end
(* The two proxy objects *)
class c obj =
let o = new _c obj in
object
method get_c' = (o#get_c' : _c' :> ct')
method m = o#m
end
class c' obj =
let o = new _c' obj in
object
method get_c = (o#get_c : _c :> ct)
method m' = o#m'
end
end
;;
--
----------------------------------------------------------------
Real name: Claudio Sacerdoti Coen
PhD Student in Computer Science at University of Bologna
E-mail: sacerdot@cs.unibo.it
http://caristudenti.cs.unibo.it/~sacerdot
----------------------------------------------------------------
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next reply other threads:[~2002-01-22 17:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-22 17:26 Claudio Sacerdoti Coen [this message]
2002-01-31 0:09 ` 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=20020122182621.B8021@cs.unibo.it \
--to=sacerdot@cs.unibo.it \
--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