Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Re: [Caml-list] Polymorphic values in local modules
@ 2010-02-03 10:05 Tiphaine Turpin
  2010-02-03 11:35 ` Alain Frisch
  0 siblings, 1 reply; 2+ messages in thread
From: Tiphaine Turpin @ 2010-02-03 10:05 UTC (permalink / raw)
  To: caml-list

Hans Ole Rafaelsen a écrit :

> 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
>
> let test f =
>  let module Foo : Foo_sig =
>      struct
>    let foo = f
>      end
>  in
>    ()
The problem here is that the test function itself is not typeable
(because the 'a parameter would have to be quantified under an arrow,
which the type system does not directly allows.
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
   ()

Tiphaine




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-02-03 11:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-03 10:05 [Caml-list] Polymorphic values in local modules Tiphaine Turpin
2010-02-03 11:35 ` Alain Frisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox