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=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id A7C19BBAF for ; Mon, 7 Jul 2008 23:09:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQAANUickjUGyojmmdsb2JhbACBW5EBAQEBAQEIBQgHEQOYWYU7 X-IronPort-AV: E=Sophos;i="4.30,318,1212357600"; d="scan'208";a="12907103" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 07 Jul 2008 23:09:58 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m67L9rIf025041 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 7 Jul 2008 23:09:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQAANUickjUGyojmmdsb2JhbACBW5EBAQEBAQEIBQgHEQOYWYU7 X-IronPort-AV: E=Sophos;i="4.30,318,1212357600"; d="scan'208";a="12907102" Received: from smtp5-g19.free.fr ([212.27.42.35]) by mail2-smtp-roc.national.inria.fr with ESMTP; 07 Jul 2008 23:09:58 +0200 Received: from smtp5-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp5-g19.free.fr (Postfix) with ESMTP id 097283F6389 for ; Mon, 7 Jul 2008 23:09:58 +0200 (CEST) Received: from localhost.localdomain (c5850-a2-3-62-147-9-250.dial.proxad.net [62.147.9.250]) by smtp5-g19.free.fr (Postfix) with ESMTP id 52AF13F6376 for ; Mon, 7 Jul 2008 23:09:57 +0200 (CEST) Date: Mon, 7 Jul 2008 21:11:33 +0200 From: Fabrice Marchant To: caml-list@inria.fr Subject: Re: [Caml-list] functions' recursive construction Message-ID: <20080707211133.21ee2905@free.fr> In-Reply-To: <48727BA5.1010806@ed.ac.uk> References: <20080707200128.4e125865@free.fr> <48727BA5.1010806@ed.ac.uk> X-Mailer: Claws Mail 3.2.0 (GTK+ 2.12.10; i486-pc-linux-gnu) X-Face: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 48728621.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; recursive:01 filliatre:01 nesting:01 runtime:01 wrote:01 integer:01 caml-list:01 argument:02 encoding:02 encoding:02 parameters:03 let:03 let:03 types:05 thread:06 Jeremy Yallop wrote: > Here's a rather simple way to do it by encoding all the mechanics in the > integer argument rather than in "f". Like Jean-Christophe Filliatre in > the original thread, I'll use a zero-based rather than a one-based encoding. > > let z v = v > let s n _ = n > let f n = n > > Now > > f z 0 > => 0 > > and > > f (s (s (s z))) 0 1 2 3 > => 3 > > and so on. Thanks Jeremy, That is really nice ! I discover this original way of thinking. 's' nesting level remains however frozen at runtime. A cool thing is that parameters types can be freely mixed : f (s (s z)) '0' "1" (fun x -> 2*x) 3 => 6 Regards, Fabrice