[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2010-02-03 (11:35) |
From: | Alain Frisch <alain@f...> |
Subject: | Re: [Caml-list] Polymorphic values in local modules |
On 03/02/2010 11:05, Tiphaine Turpin wrote: > It is possible however, provided you wrap the argument inside a > polymorphic record field (or object) as follows: > > type t = {f : 'a. 'a -> 'a} > > let test f = > let module Foo : Foo_sig = > struct > let foo = f.f > end > in > () Another option (that will be available in OCaml 3.12) is to build the module as a first-class value outside the function "test". ================================= module type Foo_sig = sig val f: 'a -> 'a end let test foo = let module Foo = (val foo : Foo_sig) in (* use the polymorphic function here... *) () let () = let foo_impl = (module struct let f a = a end : Foo_sig) in test foo_impl ================================= The type for test is: val test : (module Foo_sig) -> unit Alain