caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Rephrasing of dynamic module selection problem
@ 2006-02-21  0:54 Nathan Cooprider
  2006-02-21  3:49 ` "ocaml_beginners"::[] " Martin Jambon
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nathan Cooprider @ 2006-02-21  0:54 UTC (permalink / raw)
  To: ocaml_beginners, caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-02-21  9:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-21  0:54 Rephrasing of dynamic module selection problem Nathan Cooprider
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).