From: Andrej Bauer <Andrej.Bauer@fmf.uni-lj.si>
To: Loup Vaillant <loup.vaillant@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Unexpected restriction in "let rec" expressions
Date: Wed, 27 Feb 2008 09:53:07 +0100 [thread overview]
Message-ID: <47C524F3.9030005@fmf.uni-lj.si> (raw)
In-Reply-To: <6f9f8f4a0802260424o5bce2fd9i89fbfa38bb239a6a@mail.gmail.com>
Loup Vaillant wrote:
> loop :: ((a,c) -> (b,c)) -> a -> b
> loop f a = b
> where (b,c) = f (a,c)
You said the above was a "so-called fixpoint operator". To see in what
sense this really is a fixpoint operator consider the type:
((a * c) -> (b * c)) -> a -> b (1)
It is equivalent (under currying-uncurrying) to
(a -> (c -> b) * (c -> c)) -> a -> b (2)
We could write down a term of this type if we had a way of going from
type c -> c to type c. More precisely, consider any term
fix : (c -> c) -> c,
where the name "fix" suggests that we will plug in a fix-point operator
at the end of the day. Before reading on, you should try to write down a
term of type (2), given that we have fix. I will bet that your brain
will produce the same solution as described below.
We can get a term of type (2) by defining
let loop' f x =
let (g, h) = f x in g (fix h)
Converting from (2) back to (1) gives us an equivalent term
let loop f x =
let f' y = (fun z -> fst (f (y, z))), (fun z -> snd (f (y, z))) in
loop' f' x
or by beta-reducing:
let loop f x =
fst (f (x, fix (fun z -> snd (f (x, z)))))
You are now free to plug in whatever you wish for fix, but presumably
you would like fix to compute fixed points. This may be somewhat
troublesome in an eager language, especially if c is not a function type.
In fact, we may recover fix from loop as follows:
let fix' f = loop (fun (_, z) -> (z, f z)) ()
To see that fix' is the same as fix, we just beta-eta reduce:
fix' f =
loop (fun (_, z) -> (z, f z)) () =
fst (fix (fun z -> f z), f (fix (fun z -> f z))) =
fix (fun z -> f z) =
fix f
Indeed, loop is a generalized fixpoint operator.
But I think the nice picture drawn by Nicolas Pouillard is worth a
thousand lambda terms.
Best regards,
Andrej
P.S. Can someone think of anything else other than a fixpoint operator
that we could use in place of fix to get an interesting program (maybe
for special cases of c, such as c = int -> int)?
next prev parent reply other threads:[~2008-02-27 8:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-26 12:24 Loup Vaillant
2008-02-26 14:04 ` [Caml-list] " Jean-Christophe Filliâtre
2008-02-26 14:18 ` Damien Doligez
2008-02-26 14:34 ` Loup Vaillant
2008-02-26 14:51 ` Gabriel Kerneis
2008-02-26 14:56 ` blue storm
2008-02-26 17:48 ` Nicolas Pouillard
2008-02-26 14:57 ` Dirk Thierbach
2008-02-27 8:53 ` Andrej Bauer [this message]
2008-02-27 9:43 ` Loup Vaillant
2008-02-27 12:02 ` Dirk Thierbach
2008-02-27 14:04 ` Loup Vaillant
2008-02-27 16:41 ` Dirk Thierbach
2008-02-27 23:32 ` Loup Vaillant
2008-02-27 19:03 ` Pal-Kristian Engstad
2008-02-27 23:46 ` Loup Vaillant
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=47C524F3.9030005@fmf.uni-lj.si \
--to=andrej.bauer@fmf.uni-lj.si \
--cc=Andrej.Bauer@andrej.com \
--cc=caml-list@inria.fr \
--cc=loup.vaillant@gmail.com \
/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