Browse thread
Rephrasing of dynamic module selection problem
- Nathan Cooprider
[
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: | Nathan Cooprider <coop@c...> |
| Subject: | Rephrasing of dynamic module selection problem |
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