From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: caml-list@margaux.inria.fr
Subject: Questions about class types
Date: Thu, 21 Nov 1996 14:57:42 +0100 [thread overview]
Message-ID: <199611211357.OAA10366@ithif18.inf.tu-dresden.de> (raw)
Hello,
I want to write a module which provides a class with some
features, say
#module type A = sig
# class b (unit)= method init : unit
# end
#end;;
but I want to implement it via a class with more features, say
#module B = struct
# class b () as self =
# val a = ()
# method init = self#f
# method f = a
# end
#end;;
Unfortunately B does not match A, because (as it is written in
the documentation under 4.9.2) one can add additional instance
variables, but no additional methods. What is the reason for
this? As you can guess I would like additional methods to get
hidden when matching a class against a class type.
The first idea is to implement f as an instance variable (of
functional type) as well, but this gets very ugly as soon as
there are some mutually recursive f's.
The next idea was to specify only a type and some
functionality, not a class ie:
#module type A' = sig
# val newb : unit -> < init : unit; .. >
#end;;
#
#module B' : A' = struct
# class b () as self =
# val a = ()
# method init = self#f
# method f = a
# end
#
# let newb () = new b ()
#end;;
The disadvantage of this approach would be that a user of A'
can't use new, because he does not have access to the class.
To my surprise it did not type check, because
Values do not match:
val newb : unit -> b
is not included in
val newb : unit -> < init : unit; .. >
Even with explicit typing newb, ie substituting
# let newb () : < init : unit; .. > = ((new b ()) : < init : unit; .. >)
I get the same error. So far I thought, that a class type is only
a abbreviation for something like < .. >. Where am I wrong?
Bye,
Hendrik Tews
-------------------------------------------------------------
e-mail: tews@tcs.inf.tu-dresden.de
www: http://www.inf.tu-dresden.de/~ht1
Console: ithif18.inf.tu-dresden.de
next reply other threads:[~1996-11-21 15:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-11-21 13:57 Hendrik Tews [this message]
1996-11-21 17:10 ` Christian Boos
1996-12-10 11:10 ` Hendrik Tews
1996-12-11 13:16 ` Jerome Vouillon
[not found] <199612171154.MAA03264@arthur.u-strasbg.fr>
1996-12-17 16:06 ` 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=199611211357.OAA10366@ithif18.inf.tu-dresden.de \
--to=tews@tcs.inf.tu-dresden.de \
--cc=caml-list@margaux.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