From: Nathan Cooprider <coop@cs.utah.edu>
To: ocaml_beginners@yahoogroups.com, caml-list@yquem.inria.fr
Subject: Rephrasing of dynamic module selection problem
Date: Mon, 20 Feb 2006 17:54:32 -0700 [thread overview]
Message-ID: <43FA64C8.1050704@cs.utah.edu> (raw)
So I am still trying to get modules to be dynamically (run-time)
selectable instead of only statically (compile-time). The closest I have
come to so far is bellow. I want to be able to choose between a set of
modules (hello1 and hello2 in this example) fairly transparently.
[coop@ender example]$ cat hello1.ml
type t = int
let of_int i =
i
let print i =
print_int i;
print_string " says Hello1\n"
[coop@ender example]$ cat hello2.ml
type t = float
let of_int i =
float_of_int i
let print i =
print_float i;
print_string " says Hello2\n"
[coop@ender example]$ cat main.ml
module Hello1 = struct
#include "hello1.ml"
end ;;
module Hello2 = struct
#include "hello2.ml"
end ;;
(* This works . . . *)
module H = Hello1
(* But I would like this to be something like this instead:
let parameter = 1
module H =
match parameter with
1 -> Hello1
| _ -> Hello2
*)
let argument = 42
let main () =
H.print (H.of_int argument) ;;
main ();;
[coop@ender example]$ cpp main.ml > foo.ml ; ocamlc foo.ml ; rm foo.ml ;
a.out
42 says Hello1
In my real application, there are five different modules (and I am
adding more after I get this working) and they have around fifty
functions in them.
Nathan
next reply other threads:[~2006-02-21 0:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-21 0:54 Nathan Cooprider [this message]
2006-02-21 3:49 ` "ocaml_beginners"::[] " Martin Jambon
2006-02-21 3:55 ` [Caml-list] " brogoff
2006-02-21 9:07 ` Andreas Rossberg
2006-02-21 9:55 ` Virgile Prevosto
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=43FA64C8.1050704@cs.utah.edu \
--to=coop@cs.utah.edu \
--cc=caml-list@yquem.inria.fr \
--cc=ocaml_beginners@yahoogroups.com \
/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