From: Andrej Bauer <Andrej.Bauer@andrej.com>
To: skaller <skaller@users.sourceforge.net>, Caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] Coinductive semantics
Date: Sat, 21 Jan 2006 19:36:08 +0100 [thread overview]
Message-ID: <43D27F18.9030102@andrej.com> (raw)
In-Reply-To: <1137790790.15137.39.camel@rosella>
skaller wrote:
> How would you decode an Andrej sum without a conditional
> control transfer?
The control is a consequence of the fact that natural numbers are an
inital algebra (I am pretending that "int" denotes natural numbers). In
a programming language the initiality of natural numbers manifests
itself as an operation "rec" with which we may define function by simple
recursion, i.e, given x : 'a and f : int -> 'a, the expression "rec x f"
has they type int -> 'a and satisfies:
rec x f 0 = x
rec x f (n+1) = f (rec x f n)
Since I suggested that we use 0 and 1 as tags for variants, we could
define a deconstructor "match" for sums (i.e. the conditional control
transfer for the sum type) using rec as follows:
match g h (t, x, y) = rec (g x) (fun _ -> h y) t
The above match has the property that
match g h (0, x, y) = g x
match g h (1, x, y) = h y
There are a few details about eager/lazy evaluation of rec which I will
let you sort out (in case rec is "too eager", we use thunking).
Andrej
next prev parent reply other threads:[~2006-01-21 18:35 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-05 18:23 Alessandro Baretta
2006-01-05 19:48 ` [Caml-list] " David Baelde
2006-01-06 13:12 ` Andrej Bauer
2006-01-10 11:10 ` Francisco J. Valverde Albacete
2006-01-11 8:34 ` Hendrik Tews
2006-01-11 12:19 ` skaller
2006-01-11 14:54 ` Andrej Bauer
2006-01-12 2:10 ` skaller
2006-01-12 14:03 ` Andrej Bauer
2006-01-12 21:54 ` skaller
2006-01-13 10:23 ` Hendrik Tews
2006-01-13 14:42 ` skaller
2006-01-18 12:58 ` Hendrik Tews
2006-01-18 14:22 ` skaller
2006-01-20 0:49 ` William Lovas
2006-01-20 9:57 ` Andrej Bauer
2006-01-20 18:59 ` William Lovas
2006-01-20 20:59 ` skaller
2006-01-21 18:36 ` Andrej Bauer [this message]
2006-01-22 3:16 ` skaller
2006-01-22 12:23 ` Andrej Bauer
2006-01-22 15:35 ` skaller
2006-01-22 17:26 ` Kenn Knowles
2006-01-22 21:52 ` Andrej Bauer
2006-01-21 19:06 ` Andrej Bauer
2006-01-13 10:40 ` Andrej Bauer
[not found] ` <43C7B17A.1070503@barettadeit.com>
2006-01-14 16:53 ` Andrej Bauer
2006-01-05 20:38 Don Syme
2006-01-06 15:33 ` Alessandro Baretta
2006-01-08 10:02 ` Andrej Bauer
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=43D27F18.9030102@andrej.com \
--to=andrej.bauer@andrej.com \
--cc=caml-list@inria.fr \
--cc=skaller@users.sourceforge.net \
/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