List Info

Thread: "ocaml_beginners"::[] Replacing module without replacing file




"ocaml_beginners"::[] Replacing module without replacing file
country flaguser name
Germany
2007-03-20 01:07:12

Hi,
I have a numerical code that is intialised by functions from only one
module. As this initialisation depends on my problem, I'd like to
replace that file every now and then. Now my problem is that I don't
want to always copy around files which I would have to if I wanted to
keep the file name (i.e. module name) the same. Therefore I'd like to
have files init-problema.ml, init-problemb.ml as different files for
different problems where I just compile/link in the right one in my
makefile. However, to be able to open the module in my code, I have to
be able to keep the module name independent from the file name. Is that
possible at all? If not, does anybody have other suggestions?

Cheers,
Christian

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Re: Replacing module without replacing file
country flaguser name
United States
2007-03-20 01:17:34



Hi Christian,

here's what I would do :

-I would not make the module name independent from the
filename. Instead, I would have files like this :

File init_Problem_Version_A.ml
File init_Problem_Version_B.ml
File init_Problem.ml

and the contents of File init_Problem.ml would be something like

let current_implementation="A";;

let this_val=match current_implementation with
"A"->Init_Problem_Version_A.this_val
"B"->Init_Problem_Version_B.this_val
|x->failwith("unknown implementation");;

let that_val=match current_implementation with
"A"->Init_Problem_Version_A.that_val
"B"->Init_Problem_Version_B.that_val
|x->failwith("unknown implementation");;

When you want to switch implementations, you
just have to change the definition of "current_implementation"
in one place and then recompile using make.

HTH,

Ewan


--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Christian Lerrahn <ocaml...> wrote:
&gt;
> Hi,
> I have a numerical code that is intialised by functions from only one
> module. As this initialisation depends on my problem, I'd like to
> replace that file every now and then. Now my problem is that I don't
&gt; want to always copy around files which I would have to if I wanted to
> keep the file name (i.e. module name) the same. Therefore I'd like to
> have files init-problema.ml, init-problemb.ml as different files for
> different problems where I just compile/link in the right one in my
> makefile. However, to be able to open the module in my code, I have to
> be able to keep the module name independent from the file name. Is that
>; possible at all? If not, does anybody have other suggestions?
>
> Cheers,
> Christian
>

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Re: Replacing module without replacing file
country flaguser name
United States
2007-03-20 22:28:56

I'm not 100% sure this will work. You might have to turn off some
compiler warnings or something.

module Init_Problem = Init_ProblemA
module Init_Problem = Init_ProblemB
module Init_Problem = Init_ProblemC
....

open Init_Problem

The last binding of module Init_Problem that worked will be the one
that's open. At least that's my idea. It's worth a try I suppose.
Perhaps there's a more elegant solution out there though.

Jeff

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Replacing module without replacing file
country flaguser name
United Kingdom
2007-03-28 19:25:29

On Tuesday 20 March 2007 06:07, Christian Lerrahn wrote:
&gt; ...init-problema.ml...

Not answering your question but noting a danger: you must discipline yourself
to use valid OCaml module names as filenames. So don't use the "-&quot; char.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

__._,_.___
.

__,_._,___
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )