From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q1DNXdTt022113 for ; Tue, 14 Feb 2012 00:33:39 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwDAIOdOU+7SSC4nGdsb2JhbABDgw2tESIBAQEBAQgLEhQngiARQD0WGAMCAQIBDgsCATwIAQGhKaAii0YIJgUFBQcBBQQDBAQHDgYBAwIMBxQGgxICTAUkVoMdBJU4hVRfjEM X-IronPort-AV: E=Sophos;i="4.73,413,1325458800"; d="scan'208";a="144091750" Received: from mta112.f1.k8.com.br ([187.73.32.184]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Feb 2012 00:33:24 +0100 Received: from localhost (localhost [127.0.0.1]) by smtpz.f1.k8.com.br (Postfix) with ESMTP id DF4B1801CE for ; Mon, 13 Feb 2012 23:33:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at k8.com.br Received: from smtpz.f1.k8.com.br ([127.0.0.1]) by localhost (mta112.f1.k8.com.br [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Jd-7JKv-fIuP for ; Mon, 13 Feb 2012 23:33:21 +0000 (UTC) Received: from [192.168.1.5] (unknown [177.98.64.95]) by smtpz.f1.k8.com.br (Postfix) with ESMTPA id A0C0880070 for ; Mon, 13 Feb 2012 23:33:21 +0000 (UTC) Message-ID: <4F399DD5.3000507@digirati.com.br> Date: Mon, 13 Feb 2012 21:33:41 -0200 From: Andre Nathan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0) Gecko/20120129 Thunderbird/10.0 MIME-Version: 1.0 To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Caml-list] What am I reinventing here? Hello I have some code that behaves like the following. module M = struct type ('a, 'b) ops = { bar_of_foo : 'a -> 'b; foo_of_bar : 'b -> 'a } let foo ops x = ops.bar_of_foo x let bar ops x = ops.foo_of_bar x end type foo = A | B type bar = C | D let ops = { M.bar_of_foo = (function A -> C | B -> D); M.foo_of_bar = (function C -> A | D -> B) } let () = match M.foo ops A with | C -> () | D -> () The idea is to parametrize the behavior of some module M on two types and a set of operations involving these two types, with the catch that I want to keep the ability to pattern-match on the possible values of these types in the code that handles the return values from the functions exported by M. With the scheme above I can do this, but passing a table of functions around doesn't look very nice. Is there any way I can use functors to do what this code does, while still being able to use pattern-matching? Would I have to resort to objects to be able to do this? Thanks in advance, Andre