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 7233EBBAF for ; Wed, 3 Feb 2010 10:39:23 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIBAA3TaEuB8ApGmWdsb2JhbACbQQEBAQEBCAsKBxO8FoRFBA X-IronPort-AV: E=Sophos;i="4.49,397,1262559600"; d="scan'208";a="50929481" Received: from mail-forward1.uio.no ([129.240.10.70]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 03 Feb 2010 10:39:23 +0100 Received: from exim by mail-out1.uio.no with local-bsmtp (Exim 4.69) (envelope-from ) id 1Ncbhi-0005qq-Ag for caml-list@inria.fr; Wed, 03 Feb 2010 10:39:22 +0100 Received: from mail-mx3.uio.no ([129.240.10.44]) by mail-out1.uio.no with esmtp (Exim 4.69) (envelope-from ) id 1Ncbhi-0005qn-9b for caml-list@inria.fr; Wed, 03 Feb 2010 10:39:22 +0100 Received: from [128.39.37.254] (helo=[192.168.100.135]) by mail-mx3.uio.no with esmtpsa (TLSv1:AES256-SHA:256) user hans (Exim 4.69) (envelope-from ) id 1Ncbhh-000719-Uo for caml-list@inria.fr; Wed, 03 Feb 2010 10:39:22 +0100 Message-ID: <4B694449.10706@simula.no> Date: Wed, 03 Feb 2010 10:39:21 +0100 From: Hans Ole Rafaelsen User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: caml-list@inria.fr Subject: Polymorphic values in local modules Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-UiO-Ratelimit-Test: rcpts/h 1 msgs/h 1 sum rcpts/h 1 sum msgs/h 1 total rcpts 1104 max rcpts/h 13 ratelimit 0 X-UiO-Spam-info: not spam, SpamAssassin (score=-5.0, required=5.0, autolearn=disabled, UIO_MAIL_IS_INTERNAL=-5, uiobl=NO, uiouri=NO) X-UiO-Scanned: 9BB47408813741F6C8C3BDF19CE1CA78FADF7026 X-UiO-SPAM-Test: remote_host: 128.39.37.254 spam_score: -49 maxlevel 80 minaction 2 bait 0 mail/h: 21 total 17792 max/h 66 blacklist 0 greylist 0 ratelimit 0 X-Spam: no; 0.00; rafaelsen:01 foo:01 sig:01 sig:01 val:01 foo:01 impl:01 struct:01 impl:01 struct:01 mismatch:01 val:01 rewriting:01 polymorphic:01 polymorphic:01 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 If I have a function definition: let foo_impl a = a I'm allowed to write: let _ = let module Foo : Foo_sig = struct let foo = foo_impl end in () However I want to have a function that creates the module and take the "foo_impl" as argument: let test f = let module Foo : Foo_sig = struct let foo = f end in () and then later I would like to use it like: let _ = test foo_impl However, compiling it fails with: Error: Signature mismatch: Modules do not match: sig val foo : '_a end is not included in Foo_sig Values do not match: val foo : '_a is not included in val foo : 'a -> 'a Is there some trick to force f to have ('a -> ')? I have tried with "let test (f : 'a -> 'a)" but then it complains that f has type ('_a -> '_a). Any other suggestions/design patterns for solving these situations, without rewriting the whole structure of the application, would also be highly appreciated. Thanks, Hans