Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Conditional Modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list] Conditional Modules
On 04 Aug 2004, at 07:58, Ross Duncan wrote:
>
> Forgive me for asking what might be an easy question, I am just a 
> beginner with Ocaml.  I want to do something like this:
>
> module M = if arg then M1 else M2
> module A = F (M)
> (* define rest of program using fields of A *)
>
> The idea being that arg will come from e.g. the command line, and 
> modules M1, M2 and functor F are defined elsewhere.
>
> Of course "module M = if ...  " is a syntax error.   My question is: 
> how to achieve this behaviour (and generalisations of it) in ocaml?
>
> It seems that this is an obvious thing to want to do but I haven't 
> found any clues in the manual or the FAQs.  Is it me?

This is one of those cases where using classes and objects is the right 
way to go.

	class type c = object ... end
	class c1 : c
	class c2 : c

	module M: sig val c: c end
	module A(sig val c: c end): sig ... end


$B!=(B $B!h(B

-------------------
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