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=1.3 required=5.0 tests=SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 88A51BC37 for ; Wed, 14 Oct 2009 12:40:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai8CAGlH1UrVpUAUi2dsb2JhbACbBwEBAQoLCgcRBb1ChC0EgVs X-IronPort-AV: E=Sophos;i="4.44,556,1249250400"; d="scan'208";a="48573584" Received: from mail.gmx.net ([213.165.64.20]) by mail4-smtp-sop.national.inria.fr with SMTP; 14 Oct 2009 12:40:58 +0200 Received: (qmail invoked by alias); 14 Oct 2009 10:40:57 -0000 Received: from ip-88-153-44-66.unitymediagroup.de (EHLO mail.gmx.net) [88.153.44.66] by mail.gmx.net (mp070) with SMTP; 14 Oct 2009 12:40:57 +0200 X-Authenticated: #20429361 X-Provags-ID: V01U2FsdGVkX1/KEUUxrLjKVXDiG4VL5439H8ON/GmkQa4nPxPR3p AOXffegzoEQol3 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: caml-list@yquem.inria.fr Subject: How to add () to function parameters Date: Wed, 14 Oct 2009 12:44:17 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Till Crueger" Message-ID: User-Agent: Opera Mail/10.00 (Linux) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.67 X-Spam: no; 0.00; ocaml:01 node:01 blog:98 closures:01 closures:01 functions:01 functions:01 parentheses:01 closure:01 arbitrary:02 argument:02 parameter:02 cps:02 seems:03 unit:03 Hi, I am looking for a way to add a unit parameter to a function that takes an arbitrary number of parameters. If the number of parameters is known this is fairly easy and I can just do: let lift1 f a = fun () -> f a;; let lift2 f a b = fun () -> f a b;; (all these create one closure per lifting) etc... However it is a bit of a hassle to have to code each of these lifts... So what I am looking for is a way to extend this pattern to all numbers. So far I got to the point that I can do the following: let lift_once f a = fun () -> f a;; let lift_more f a = fun () -> f () a;; So for a function f taking two parameters a and b I can do lift_more (lift_once f a) b (two closures created) and for a function taking the parameters a, b and c I can do lift_more (lift_more (lift_once f a) b) c (three closures created) to get the lifted functions. However this solution gets quite ugly with all the parentheses. Also there are a lot of closures being produced and evaluated for any single lifting. I had a look at the Jane Street blog post about variable argument functions (http://ocaml.janestcapital.com/?q=node/22), which seems to do similar things. However I have never been really good with CPS, so I don't know if those techniques can be applied to this problem. Is there any way to do this, which does not get this ugly. Also the resulting lifted function should not contain too many closures. Thanks for your help, Till