From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 5F76BBBAF for ; Wed, 3 Feb 2010 12:35:14 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsQBAPftaEvB/Bd4kGdsb2JhbACbQQEBAQEJCQwHEwO8KoRFBA X-IronPort-AV: E=Sophos;i="4.49,397,1262559600"; d="scan'208";a="50951283" Received: from smtp-msa-out01.orange.fr ([193.252.23.120]) by mail1-smtp-roc.national.inria.fr with ESMTP; 03 Feb 2010 12:35:14 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf5a03.orange.fr (SMTP Server) with ESMTP id 178981C0032C; Wed, 3 Feb 2010 12:35:14 +0100 (CET) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf5a03.orange.fr (SMTP Server) with ESMTP id 074491C00327; Wed, 3 Feb 2010 12:35:14 +0100 (CET) Received: from [192.168.1.53] (APuteaux-154-1-16-70.w83-199.abo.wanadoo.fr [83.199.17.70]) by mwinf5a03.orange.fr (SMTP Server) with ESMTP id A83C61C0032C; Wed, 3 Feb 2010 12:35:13 +0100 (CET) X-ME-UUID: 20100203113513689.A83C61C0032C@mwinf5a03.orange.fr X-ME-User-Auth: lexifi Message-ID: <4B695F73.50803@frisch.fr> Date: Wed, 03 Feb 2010 12:35:15 +0100 From: Alain Frisch User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20100111 Lightning/1.0b1 Thunderbird/3.0.1 MIME-Version: 1.0 To: Tiphaine Turpin Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Polymorphic values in local modules References: <4B694A55.2040100@irisa.fr> In-Reply-To: <4B694A55.2040100@irisa.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; frisch:01 frisch:01 foo:01 foo:01 sig:01 struct:01 ocaml:01 sig:01 val:01 val:01 impl:01 struct:01 impl:01 polymorphic:01 polymorphic:01 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