From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA15269; Mon, 15 Mar 2004 13:34:21 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA15147 for ; Mon, 15 Mar 2004 13:34:20 +0100 (MET) Received: from eris.rz.uni-saarland.de (eris.rz.uni-saarland.de [134.96.7.8]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i2FCYJHd004024 for ; Mon, 15 Mar 2004 13:34:19 +0100 Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.254.254]) by eris.rz.uni-saarland.de (SGI-8.12.5/8.12.10) with ESMTP id i2FCYHE2389816; Mon, 15 Mar 2004 13:34:17 +0100 (CET) Received: from mail.cs.uni-sb.de (mail.cs.uni-sb.de [134.96.254.200]) by cs.uni-sb.de (8.12.11/2003091100) with ESMTP id i2FCYGEi011175; Mon, 15 Mar 2004 13:34:16 +0100 (CET) Received: from ps.uni-sb.de (grizzly.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.12.11/2003073000) with ESMTP id i2FCYFsn000253; Mon, 15 Mar 2004 13:34:15 +0100 (CET) X-Authentication-Warning: email: Host grizzly.ps.uni-sb.de [134.96.186.68] claimed to be ps.uni-sb.de Received: from ps.uni-sb.de (groove.ps.uni-sb.de [134.96.186.172]) by ps.uni-sb.de (8.12.10/8.12.10) with ESMTP id i2FCYElT013113; Mon, 15 Mar 2004 13:34:14 +0100 Message-ID: <4055A2C6.9070608@ps.uni-sb.de> Date: Mon, 15 Mar 2004 13:34:14 +0100 From: Andreas Rossberg User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en MIME-Version: 1.0 To: ronniec95@lineone.net CC: caml-list@inria.fr Subject: Re: [Caml-list] Module/functor question References: <20040314190527.GA1898@cradle> <20040315.042218.07646200.yoriyuki@mbg.ocn.ne.jp> <20040314234630.GA2668@cradle> In-Reply-To: <20040314234630.GA2668@cradle> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiVirus: checked by AntiVir Milter 1.0.6; AVE 6.24.0.6; VDF 6.24.0.56 X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; rossberg:01 rossberg:01 uni-sb:01 caml-list:01 functor:01 ronniec:01 lineone:01 mli:01 'type:99 mli:01 val:01 val:01 originator:99 struct:01 uni-sb:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 136 ronniec95@lineone.net wrote: > > I've copied the exact code below since it's not that long. I wonder > about header.mli which has 'type t=u' in it which was the only way of > getting it all to fit together. Why do I have to do that? You don't have to, if you declare the types at the right places, i.e. inside the modules. Actually, you don't need the local modules at all, since compilation units are already modules. Here is the sketch of a simplified version (not tested). (* header.mli *) type t val as_xml : t -> Xml.xml val create : Xml.xml -> t val make : ?version:int -> ?msgtypeid:int -> string -> string -> string -> t (* header.ml *) type t = { version : int; created : Calendar.t; environment : string; msgtypeid : int; msgtype : string; originatorid : string; machineid: string; } let as_xml d = ... let create (root:Xml.xml) : t = ... let make ?(version = 1) ?(msgtypeid=1) msgtype originator env = ... (* main.ml *) module type CONSTRUCTOR = sig type t val as_xml : t -> Xml.xml val create : Xml.xml -> t end module MessageSender (C : CONSTRUCTOR) = struct let send msg = print_string (Xml.to_string (C.as_xml msg)) end let _ = let module M = MessageSender(Header) in M.send (Header.make "Header" "TestMessage" "DEV") -- Andreas Rossberg, rossberg@ps.uni-sb.de Let's get rid of those possible thingies! -- TB ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners