* Local module as let binding around class def?
@ 2000-01-17 22:49 Brian Rogoff
0 siblings, 0 replies; only message in thread
From: Brian Rogoff @ 2000-01-17 22:49 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-01-18 10:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-17 22:49 Local module as let binding around class def? Brian Rogoff
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).