From: michael-grunewald@wanadoo.fr (Michaël Grünewald)
To: caml-list@inria.fr
Subject: [Caml-list] Re: load modules by name
Date: 22 Jan 2003 17:41:35 +0100 [thread overview]
Message-ID: <87y95duog0.fsf@ketanu.dyndns.org> (raw)
In-Reply-To: <20030121072228.GA6481@anu.edu.au>
Pietro Abate <Pietro.Abate@anu.edu.au> writes:
> hi list,
>
> I'm trying to figure out how I can build a kind of associative list
> to load a specific module at runtime. I've reread few old messages about
> first-class modules and other oddities, but I've the sensation my
> problem is easier.
>
> I have a library (compiled), an application (compiled) and a bunch of
> user defined modules (that are compiled as well, but these may be vary
> in number). At the moment the application select the rigth module
> statically regarding a command line argument. However this way I must
> 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 -> 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 <michael-grunewald@wanadoo.fr>
-------------------
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
prev parent reply other threads:[~2003-01-23 10:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-21 7:22 [Caml-list] " Pietro Abate
2003-01-21 10:48 ` Stefano Zacchiroli
2003-01-22 16:41 ` Michaël Grünewald [this message]
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=87y95duog0.fsf@ketanu.dyndns.org \
--to=michael-grunewald@wanadoo.fr \
--cc=caml-list@inria.fr \
/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