From: Tony Edgin <edgin@slingshot.co.nz>
To: caml-list@inria.fr
Subject: [Caml-list] Narrowing class's public interface
Date: Wed, 13 Oct 2004 11:16:12 +1300 [thread overview]
Message-ID: <200410131116.12485.edgin@slingshot.co.nz> (raw)
What is the reasoning behind Ocaml not allowing the public methods of a class
to be hidden?
Some times its nice for a class to have "global" public methods (Java's public
methods) as well as public methods local to its module (Java's unprefixed
methods). This allows for progressive encapsulation, where more distance
modules no very little about a class, while the more local modules know more
about the class. Inheritance could be used to approximate this, but
sometimes subtyping makes more sense.
I apologize for my lack of clarity. For those who couldn't understand my
question, here's an example.
module RandomVariables =
struct
class type rv_type =
object
method instance : float
method scale_by : float -> rv_type
method add : rv_type -> rv_type
end
class gaussian _stdev _mean =
object
method stdev = _stdev
method mean = _mean
method instance = (* elided *)
(** Returns a draw from the corresponding distribution.
*)
method scale_by a =
new gaussian ((abs_float a)*._stdev) (a*._mean)
method add (other : guassian) =
let sigma = sqrt (_stdev**2. +. other#stdev**2.)
and mu = _mean +. other#mean
in
new gaussian sigma mu
end
(* Truncated *)
end
(* Bad code which I would like to use *)
class gaussian_rv =
(RandomVariables.gaussian float -> float -> RandomVariables.rv_type)
;;
cheers.
--
Tony Edgin
CARP
-------------------
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 reply other threads:[~2004-10-12 22:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-12 22:16 Tony Edgin [this message]
2004-10-13 0:49 ` Jacques Garrigue
2004-10-13 1:43 ` John Prevost
2004-10-13 2:27 ` skaller
2004-10-13 6:39 ` John Prevost
2004-10-13 7:34 ` skaller
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=200410131116.12485.edgin@slingshot.co.nz \
--to=edgin@slingshot.co.nz \
--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