Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Tiphaine Turpin <Tiphaine.Turpin@irisa.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Polymorphic values in local modules
Date: Wed, 03 Feb 2010 11:05:09 +0100	[thread overview]
Message-ID: <4B694A55.2040100@irisa.fr> (raw)

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




             reply	other threads:[~2010-02-03 10:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-03 10:05 Tiphaine Turpin [this message]
2010-02-03 11:35 ` Alain Frisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B694A55.2040100@irisa.fr \
    --to=tiphaine.turpin@irisa.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox