From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Fabrice Marchant <fabricemarchant@free.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] functions' recursive construction
Date: Mon, 07 Jul 2008 21:25:09 +0100 [thread overview]
Message-ID: <48727BA5.1010806@ed.ac.uk> (raw)
In-Reply-To: <20080707200128.4e125865@free.fr>
Fabrice Marchant wrote:
> On Wed, 23 May 2007 01:17:08 +0200 "Damien Lefortier"
> <damien.lefortier@gmail.com> 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.
next prev parent reply other threads:[~2008-07-07 20:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-22 23:17 Damien Lefortier
2007-05-22 23:21 ` [Caml-list] " Jon Harrop
2007-05-22 23:31 ` Lukasz Stafiniak
2007-05-22 23:32 ` Lukasz Stafiniak
2007-05-22 23:41 ` Jon Harrop
2007-05-23 6:25 ` Jean-Christophe Filliatre
2008-07-07 18:01 ` Fabrice Marchant
[not found] ` <a58674cc0807071304x1640d670sde3045a0920a5922@mail.gmail.com>
2008-07-07 18:28 ` Fabrice Marchant
2008-07-07 20:40 ` Jeremy Yallop
[not found] ` <C3DD7276-23D5-41BE-A272-7579586A5559@gmail.com>
2008-07-07 18:36 ` Fabrice Marchant
2008-07-07 20:25 ` Jeremy Yallop [this message]
2008-07-07 19:11 ` Fabrice Marchant
2008-07-07 22:48 ` asmadeus77
2008-07-08 9:24 ` Daniel Bünzli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48727BA5.1010806@ed.ac.uk \
--to=jeremy.yallop@ed.ac.uk \
--cc=caml-list@yquem.inria.fr \
--cc=fabricemarchant@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).