caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Polymorphic values in local modules
@ 2010-02-03  9:39 Hans Ole Rafaelsen
  0 siblings, 0 replies; only message in thread
From: Hans Ole Rafaelsen @ 2010-02-03  9:39 UTC (permalink / raw)
  To: caml-list

Hi,

I'm trying to construct a module that have a function taking polymorphic 
arguments. I want to use this module as a local module in different 
places, where the function implementation is different. The module has 
the signature:

module type Foo_sig =
sig
  val foo : 'a -> 'a
end

If I have a function definition:

let foo_impl a =
  a

I'm allowed to write:
let _ = let module Foo : Foo_sig =
        struct
          let foo = foo_impl
        end
        in
           ()

However I want to have a function that creates the module and take the 
"foo_impl" as argument:
let test f =
  let module Foo : Foo_sig =
      struct
    let foo = f
      end
  in
    ()

and then later I would like to use it like:
let _ = test foo_impl

However, compiling it fails with:
Error: Signature mismatch:
       Modules do not match: sig val foo : '_a end is not included in 
Foo_sig
       Values do not match:
         val foo : '_a
       is not included in
         val foo : 'a -> 'a

Is there some trick to force f to have ('a -> ')? I have tried with "let 
test (f : 'a -> 'a)" but then it complains that f has type ('_a -> '_a). 
Any other suggestions/design patterns for solving these situations, 
without rewriting the whole structure of the application, would also be 
highly appreciated.

Thanks,

Hans




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-02-03  9:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-03  9:39 Polymorphic values in local modules Hans Ole Rafaelsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).