<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/01/a81f1cb20b0c89d47609694a59035408"
  from="michael-grunewald@w..."
  author="michael-grunewald@w..."
  date="2003-01-23T10:27:22"
  subject="[Caml-list] Re: load modules by name"
  prev="2003/01/2f8b8c3e56cbc57ad0828a8c4c361f8a"
  next="2003/01/3ec900eef42b08b0fd4f98e4b1164ef2"
  prev-in-thread="2003/01/0650f6f66d394345038598ab4b6dfae6"
  prev-thread="2003/01/2b72d4c560e6efe5525adf0843857a06"
  next-thread="2003/01/b4a8ce11a48f9cc6cbf897c6b7a41e47"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] load modules by name">
<msg 
  url="2003/01/c5aa93d21c0c93504dd2d03bd7e68762"
  from="Pietro Abate &lt;Pietro.Abate@a...&gt;"
  author="Pietro Abate"
  date="2003-01-21T07:17:01"
  subject="[Caml-list] load modules by name">
<msg 
  url="2003/01/0650f6f66d394345038598ab4b6dfae6"
  from="Stefano Zacchiroli &lt;zack@b...&gt;"
  author="Stefano Zacchiroli"
  date="2003-01-21T18:56:10"
  subject="Re: [Caml-list] load modules by name">
</msg>
<msg 
  url="2003/01/a81f1cb20b0c89d47609694a59035408"
  from="michael-grunewald@w..."
  author="michael-grunewald@w..."
  date="2003-01-23T10:27:22"
  subject="[Caml-list] Re: load modules by name">
</msg>
</msg>
</thread>

<contents>
Pietro Abate &lt;Pietro.Abate@anu.edu.au&gt; writes:

&gt; hi list,
&gt; 
&gt; I'm trying to figure out how I can build a kind of associative list
&gt; to load a specific module at runtime. I've reread few old messages about
&gt; first-class modules and other oddities, but I've the sensation my
&gt; problem is easier.
&gt; 
&gt; I have a library (compiled), an application (compiled) and a bunch of
&gt; user defined modules (that are compiled as well, but these may be vary
&gt; in number). At the moment the application select the rigth module
&gt; statically regarding a command line argument. However this way I must
&gt; recompile my application everytime I add a new module.

Why don't you build a little bunch of software that maintain a 'record
book' of given modules/files? Thus the client software find easily a
list in the 'record book', while you just need to update this book each
time you add a new algorithm into your collection (or remove one).

In the main code part, you may have a module

module Algo =
struct

    type t = int -&gt; int list (* e.g. *)
    type id = int

    let assoc = ref [] (* (id * algo) list -- assoc *)
    let subscribe a b = assoc := (a,b) :: !assoc
    let get i = List.assoc i !assoc

end

each module dynamically loaded has a registration part that says

let _ = Algo.subscription my_id my_algo

where my_id is an unique identification key known in the record book,
thus you can get back the algorithm with the Algo.get function, while
you keep away from your code any reference to hardwired module name.
-- 
Michaël Grünewald &lt;michael-grunewald@wanadoo.fr&gt;
-------------------
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

</contents>

</message>

