From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 764E8BB84 for ; Mon, 26 Jan 2009 16:16:34 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuAGAPdifUmCcUBTgWdsb2JhbACTfgEBCwcECgcRtTyFSw X-IronPort-AV: E=Sophos;i="4.37,325,1231110000"; d="scan'208";a="22037529" Received: from unknown (HELO sigma957.cis.mcmaster.ca) ([130.113.64.83]) by mail3-smtp-sop.national.inria.fr with ESMTP; 26 Jan 2009 16:16:09 +0100 Received: from Gorash7.UTS.McMaster.CA (Gorash7.UTS.mcmaster.ca [130.113.196.61]) by sigma957.cis.mcmaster.ca (8.13.7/8.13.7) with ESMTP id n0QFFg81007977; Mon, 26 Jan 2009 10:16:05 -0500 (EST) Received: from cgpsrv2.cis.mcmaster.ca (univmail.CIS.McMaster.CA [130.113.64.46]) by Gorash7.UTS.McMaster.CA (8.13.7/8.13.7) with ESMTP id n0QFFa0S012276; Mon, 26 Jan 2009 10:15:36 -0500 Received: from [129.97.169.240] (account carette@univmail.cis.mcmaster.ca [129.97.169.240] verified) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.3.12) with ESMTPA id 240118714; Mon, 26 Jan 2009 10:15:36 -0500 Message-ID: <497DD398.5030501@mcmaster.ca> Date: Mon, 26 Jan 2009 10:15:36 -0500 From: Jacques Carette User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Micha=EBl_Gr=FCnewald?= Cc: caml-list@inria.fr Subject: Re: [Caml-list] Defining a family of functors References: <497DD1F5.7050702@yahoo.fr> In-Reply-To: <497DD1F5.7050702@yahoo.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-PMX-Version-Mac: 5.4.2.338381, Antispam-Engine: 2.6.0.325393, Antispam-Data: 2009.1.26.150137 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='BODY_SIZE_1700_1799 0, BODY_SIZE_5000_LESS 0, __BOUNCE_CHALLENGE_SUBJ 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' X-Spam: no; 0.00; functors:01 higher-order:01 functor:01 functor:01 camlp:01 denotes:01 functors:01 iirc:01 ...,:98 wrote:01 caml-list:01 define:02 define:02 modules:02 binary:02 Without the projections, you can do it via a higher-order Functor which does a fold, ie lifting to the Functor level what one usually does to get an n-ary product out of a binary product. With the projections, as this involves name-generation, I don't see how to do it without using camlp4. Even my favourite sledgehammer, metocaml, can't help here. Jacques Michaël Grünewald wrote: > I am facing a situation that could be solved by ``defining a family of > functors'', I describe the problem and would be very glad to get your > views about it. > > To illustrate the situation, I will suppose A1, ..., An are modules > implementing the same signature S, let's say S contains the usual > opertations on groups (mathematical groups, you can replace this by > vector spaces, or whatever). It is easy to write a Product2 functor > > Product2: A1:S -> A2:S -> S2 > > producing an implementation for the direct product (with signature S) > of the groups A1 and A2, plus injections j1 : A1.t -> S2.t and j2: > A2.t -> S2.t and corresponding projections (the type t denotes the > module thingie, as usual). This extension of S is here written S2. > > My problem is ``how do I remove the 2'' ? Would it be possible to > define a functor scheme [:)] > > Productn: A1:S -> .. -> An:S -> Sn > > able to instantiate concrete functors for any value of n ? > > It is possible to generate automatically appropriate code for small > values of n, but I am looking for a better approach. It is simple to > get close of the solution in the object paradigm, since I can simply > put objects in an array and iterate over this array (IIRC this is the > aggregate design pattern), but I do not see an easy way to define > injections and projections.