Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] load modules by name
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-23 (10:27)
From: michael-grunewald@w...
Subject: [Caml-list] Re: load modules by name
Pietro Abate <> 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 =

    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


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 <>
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: