Version française
Home     About     Download     Resources     Contact us    
Browse thread
modules local to functions.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrew Conway <arc@l...>
Subject: modules local to functions.


Resume en tres pauvre Francais: je voudrais utiliser un "functor" au milleau
d'une fonctionne, en utilisant les parametres de la fonctionne dans le "sig".
Je ne peut pas le faire. Pourquoi pas?

---------------------------------

I have a functor such as follows:

  module type Specifyn = sig val n : int end;;

  module Makespecific(N:Specifyn) = struct
	type mytype = int
	let mirror () : mytype = N.n
  end;;

I can apply it at the main level like:

  module Fred = Makespecific(struct let n = 7 end);;

However, there are cases when I want to define a module in the middle
of a function (eg a functor of packed binary arrays where I want to 
determine the number of bits used at run time depending upon the 
arguement of the function). That is, I would like to be abe to do:

  let toto digits =
	module Fred = Makespecific(struct let n = digits end) in
	Fred.mirror ();;

which seems to be reasonably within the spirit and syntax of csl. 
Even if that is not possible, something else like:

   let toto digits =
	let u = Makespecific(struct let n = digits end).mirror () in
	u
   ;;

would also be useful although not an entirely satisfactory solution.

Is this plausible? I seem to remember a discussion something along this
line a while ago, but it may have been for sml.

Thanks for making csl available,

Andrew.