caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@best.com>
To: caml-list@inria.fr
Subject: Local module as let binding around class def?
Date: Mon, 17 Jan 2000 14:49:26 -0800 (PST)	[thread overview]
Message-ID: <Pine.BSF.4.21.0001171437450.3496-100000@shell5.ba.best.com> (raw)

This question was probably asked before, but I couldn't find the answer
from a quick perusal of the list. 

I take it that it is not legal to use a local module instantiation as 
the "let binding" around a class definition. Could someone explain the 
reason for the restriction, and the nicest workaround? This comes up when 
I want to make OO renamings for functorial ADTs. To be concrete, if I have 
a functorially defined ADT "Seq", like Set in the standard lib, and I'd
like to make an class Oseq.c, which has a Seq.t representation and whose
methods are just the various Seq functions, why can't the definition use the
functor instantiation in local module definitions, instead of copying all
of the functor code into the oseq.ml file (my current workaround)?

(* oseq.ml *)

class c () = 
  let module Element = struct type t = int end in
  let module SeqRep  = Make(Element) in 
  object
    val s = create ()
    (* Mutators *)
    method addhi (:data : int) = SeqRep.addhi s data
    method addlo (:data : int) = SeqRep.addlo s data

    (* etc, etc., ... *)
  end

(* seq.ml *)

(*** Functorial interface *)

module type ElementType =
  sig
    type t
  end

(* The input signature of the functor [Seq.Make].*)

module type S =
  sig
    type elem_t
    type t

    (* Constructors *)
    val create: unit -> t
    val make: unit -> t
    val of_array: elem_t array -> t
    val of_list: elem_t list -> t

    (* Mutators *)
    val addhi: t -> elem_t -> unit
    val addlo: t -> elem_t -> unit
    val remhi: t -> unit
    val remlo: t -> unit
    val set: t -> int -> elem_t -> unit

    (* Selectors *)
    val get: t -> int -> elem_t
    val to_array: t -> elem_t array
    val to_list: t -> elem_t list
    val last: t -> elem_t
    val length: t -> int
  end

module Make(E : ElementType) : (S with type elem_t = E.t) = 
  struct
    type elem_t = E.t
    type t =
   (* etc .... *)
  end





                 reply	other threads:[~2000-01-18 10:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Pine.BSF.4.21.0001171437450.3496-100000@shell5.ba.best.com \
    --to=bpr@best.com \
    --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).