From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA06192 for caml-redistribution; Tue, 18 Jan 2000 11:56:30 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA02273 for ; Mon, 17 Jan 2000 23:49:30 +0100 (MET) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id XAA25133 for ; Mon, 17 Jan 2000 23:49:28 +0100 (MET) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id OAA06715 for ; Mon, 17 Jan 2000 14:49:26 -0800 (PST) Date: Mon, 17 Jan 2000 14:49:26 -0800 (PST) From: Brian Rogoff To: caml-list@inria.fr Subject: Local module as let binding around class def? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis 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