Browse thread
[Caml-list] Module/functor question
-
ronniec95@l...
-
Yamagata Yoriyuki
-
ronniec95@l...
- Andreas Rossberg
-
ronniec95@l...
-
Yamagata Yoriyuki
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andreas Rossberg <rossberg@p...> |
| Subject: | Re: [Caml-list] Module/functor question |
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