From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E654CBBAF for ; Wed, 3 Feb 2010 11:08:39 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.49,397,1262559600"; d="scan'208";a="43102466" Received: from arvin.irisa.fr (HELO [131.254.11.86]) ([131.254.11.86]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 03 Feb 2010 11:08:39 +0100 Message-ID: <4B694A55.2040100@irisa.fr> Date: Wed, 03 Feb 2010 11:05:09 +0100 From: Tiphaine Turpin User-Agent: Thunderbird 2.0.0.19 (X11/20090216) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Polymorphic values in local modules Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; irisa:01 rafaelsen:01 foo:01 sig:01 sig:01 val:01 foo:01 struct:01 quantified:01 struct:01 polymorphic:01 polymorphic:01 caml-list:01 modules:02 argument:02 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