caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Pietro.Abate@anu.edu.au
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] class type inside a sig
Date: Wed, 06 Jul 2005 19:13:36 +0900 (JST)	[thread overview]
Message-ID: <20050706.191336.45516355.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20050706092010.GA26758@pulp.anu.edu.au>

From: Pietro Abate <Pietro.Abate@anu.edu.au>

> how can I pass a generic class type inside a signature without
> actually specifying the class itself ?
> 
> this is the best I figured out :
> 
> module type S =
> sig
>    type c = < add : int -> 'c > as 'c
>    val make : unit -> c
> end
> 
> module Make ( T:S ) = struct
> 
>   (* let init = new T.c *)
>   let init = T.make ()
>   let add e = init#add e
> 
> end
>       
> but it isn't satisfactory as I've to pass a 'make' function and

This is somehow unavoidable: if you want your class type to be
generic, then you cannot be sure that its constructor will have the
right type. So it is more natural to pass it independently.

> if I try to instantiate the module with a super class of c, it gives 
> me a signature error.
[...]
> Signature mismatch:
> Modules do not match:
>   sig class c : test val make : unit -> test end
> is not included in
>   S
> Type declarations do not match:
>   type c = < add : int -> c; other : int >
> is not included in
>   type c = < add : int -> 'a > as 'a
>
> how can I achieve this ?
> 
> Basically I'd like to say: 
> type c = < add : int -> 'a; .. > as 'a

Impossible in ocaml 3.08.3.
With ocaml 3.09 (CVS version)
  type c = private < add : int -> 'a; .. > as 'a
is exactly what you are asking for.

And before someone asks, you of course cannot inherit from such a
generic class (even if it were declared as a class rather than an
object type), as there is no way to know what other public methods it
could (i.e. they might be incompatible to the ones you add inside your
functor.)

Jacques


      reply	other threads:[~2005-07-06 10:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-06  9:20 Pietro Abate
2005-07-06 10:13 ` Jacques Garrigue [this message]

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=20050706.191336.45516355.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=Pietro.Abate@anu.edu.au \
    --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;
as well as URLs for NNTP newsgroup(s).