caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Questions about class types
@ 1996-11-21 13:57 Hendrik Tews
  1996-11-21 17:10 ` Christian Boos
  0 siblings, 1 reply; 5+ messages in thread
From: Hendrik Tews @ 1996-11-21 13:57 UTC (permalink / raw)
  To: caml-list

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





^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <199612171154.MAA03264@arthur.u-strasbg.fr>]

end of thread, other threads:[~1996-12-18  7:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-21 13:57 Questions about class types Hendrik Tews
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).