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-21 (07:17)
From: Pietro Abate <Pietro.Abate@a...>
Subject: [Caml-list] load modules by name
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.

What I'd like to do is reading all .cmo files (or .ml files and compile
them on the fly) in a directory and build a kind of assoc list with 
(name,module) and at runtime select the right module.

let's say that now I have

let algo = 
match command_line_option with
| "mod1" -> Module1.algo
| "mod2" -> Module2.algo
| _ -> failwith "module not defined"
in ...

but I'd rather have something like

let algo =
		List.assoc "command_line_option" assoclist
	with Not_found -> failwith "Module not defined"
in ...

That would not require any recompilation of my application.

It would also nice to compile on the fly these modules...
I'm thinking of something like eval in perl...

is it possible ?


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: