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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 0E856BBAF for ; Mon, 7 Jul 2008 22:25:12 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQAAE4YckjUnvgImmdsb2JhbACBXJEBAQEBAQEIBQgHEQOeDA X-IronPort-AV: E=Sophos;i="4.30,318,1212357600"; d="scan'208";a="14856239" Received: from smtp.dslgb.com (HELO mcr-smtp-002.bulldogdsl.com) ([212.158.248.8]) by mail1-smtp-roc.national.inria.fr with ESMTP; 07 Jul 2008 22:25:11 +0200 Received: by mcr-smtp-002.bulldogdsl.com (Postfix, from userid 1010) id 5235D845934; Mon, 7 Jul 2008 21:25:11 +0100 (BST) Received: from [192.168.123.191] (host-84-9-233-177.dslgb.com [84.9.233.177]) by mcr-smtp-002.bulldogdsl.com (Postfix) with ESMTP id 05A64845867; Mon, 7 Jul 2008 21:25:10 +0100 (BST) Message-ID: <48727BA5.1010806@ed.ac.uk> Date: Mon, 07 Jul 2008 21:25:09 +0100 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.14 (X11/20080509) MIME-Version: 1.0 To: Fabrice Marchant Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] functions' recursive construction References: <20080707200128.4e125865@free.fr> In-Reply-To: <20080707200128.4e125865@free.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; recursive:01 damien:01 damien:01 ocaml:01 coq:01 ocaml:01 filliatre:01 wrote:01 wrote:01 rec:01 integer:01 integer:01 caml-list:01 argument:02 argument:02 Fabrice Marchant wrote: > On Wed, 23 May 2007 01:17:08 +0200 "Damien Lefortier" > wrote: > >> I try to do a function f which takes one integer argument and >> returns a function g which returns its nth arguments. >> >> For example f 3 gives g with let g = fun x -> fun y -> fun z -> z >> ;; >> >> I tried to do that kind of f function. >> >> let rec f = function 1 -> fun x -> x | n -> fun _ -> f (n-1) ;; >> >> But it does not work, any idea ? > > Sometimes, trying to learn a bit more about OCaml, I dig into old > List topics. But here, outside Coq answer, I'm not sure to understand > the explanations about the original OCaml question. Please, is it > possible to write an OCaml function that would behave the way Damien > Lefortier wish ? (I think the answer is 'No') Could you shed light on > this ? 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. Jeremy.