Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Polymorphic values in local modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tiphaine Turpin <Tiphaine.Turpin@i...>
Subject: Re: [Caml-list] Polymorphic values in local modules
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