From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA23061; Mon, 27 Oct 2003 08:12:59 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA28339 for ; Mon, 27 Oct 2003 08:12:57 +0100 (MET) Received: from avalon.ens-lsh.fr (mailhost.ens-lsh.fr [193.51.131.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9R7Cv101767 for ; Mon, 27 Oct 2003 08:12:57 +0100 (MET) Received: from avalon.ens-lsh.fr (localhost [127.0.0.1]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id h9R8CQCc014771 for ; Mon, 27 Oct 2003 08:12:26 GMT Received: from ens-notes1.ens-lsh.fr (ens-notes1.ens-lsh.fr [10.2.1.44]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id h9R8CPaA014768 for ; Mon, 27 Oct 2003 08:12:25 GMT Received: from mostha ([10.3.20.31]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2003102708125483:4913 ; Mon, 27 Oct 2003 08:12:54 +0100 Date: Mon, 27 Oct 2003 08:14:53 +0100 From: Damien Cc: Subject: Re: [Caml-list] partial eval question Message-Id: <20031027081453.37b9f6ee.Damien.Pous@ens-lyon.fr> In-Reply-To: <004a01c39c2b$819db8f0$1fcf2952@Archimedes> References: <004a01c39c2b$819db8f0$1fcf2952@Archimedes> Organization: mosthagloups X-Mailer: Sylpheed version 0.9.6claws (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 27/10/2003 08:12:54, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 27/10/2003 08:12:56, Serialize complete at 27/10/2003 08:12:56 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; damien:01 damien:01 ens-lyon:01 caml-list:01 closures:01 multi-stage:01 metaocaml:01 metaocaml:01 metaml:01 metaml:01 ocaml:01 caml:01 0000:98 rec:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 27 Oct 2003 01:41:49 -0000 Ben Kavanagh wrote: > Say I have a function such as pow defined as > > let pow n x = > let rec pow_iter (n1, x1, p1) = > if (n1 = 0) then p1 > else if (n1 mod 2 = 0) > then pow_iter(n1/2, x1*x1, p1) > else pow_iter(n1-1, x1, p1*x1) > in pow_iter(n, x, 1);; > > and I say > > let pow2 = pow 2 > > Are there any ML implementations that would automatically perform > partial evaluation to create pow2 instead of using closures, possibly > unfolding the pow_iter call? Would Caml ever have this capability? Multi-Stage Programming is your friend... There are two ML implementations : Ocaml : MetaOCaml SML : MetaML let rec pow n = .< .~(match n with | 1 -> .< fun x -> x >. | n -> .< fun x -> x * .~(pow (n-1)) x>. ) >. (pow 3) get reduced into . x*x*x>. Damien ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners