caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andrej Bauer <Andrej.Bauer@andrej.com>
To: William Lovas <wlovas@stwing.upenn.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Coinductive semantics
Date: Fri, 20 Jan 2006 10:57:39 +0100	[thread overview]
Message-ID: <43D0B413.1060806@andrej.com> (raw)
In-Reply-To: <20060120004948.GA2490@coruscant.stwing.upenn.edu>

William Lovas wrote:
> A thought: products and sums are duals, classically, but not
> intuitionistically.

This is false. Products and sums are dual concepts, both classically and
intuitionistically.

> Since O'Caml lacks classical control constructs like
> callcc, there's no redundancy having both products and sums: neither is
> representable solely using the other.

The above statement is rather vague and I am tempted to ignore it. If I
try to interpet it the best I can, it looks as if William is confusing
sums and products with unions and intersections (and is thus thinking
that complements might help in representing sums as products, using laws
of Boolean algebra).

Intersection of sets is a special case of products. Unions is a special
case of coproducts. In any Boolean algebra (hence also in the Boolean
algebra of subsets), unions and intersections may indeed be expressed in
terms of each other, using complements:

 A union B = complement (complement A intersection complement B)

where A, B are elements of a Boolean algebra. But in a general category
there is not such relationship between products and coproducts.

(By the way, unions and intersections are dual concepts even if there is
no complementation available, such as in intuitionistic set theory.)

> Also, O'Caml's datatypes are much more than just sums: they also include
> recursive types, polymorphism, pattern matching, and a degree of
> abstraction.

So? What is the point here?

In a programming language equipped with products and natural numbers,
and irrespective of what else is there, sums of (inhabited) types may be
encoded by products, as every programmer knows (at some level). For
example, to encode the following sum, which expresses the fact that
programmers are interesting characters and mathematicians may experience
instabilities,

  type person = Programmer of char | Mathematician of float

we assign constants

  let programmer = 0
  let mathematician = 1

pick two dummy values

  let dummy_c = '\0'
  let dummy_f = 0.0

and encode values of type person as values of the product type

  type person' = int * char * float

A value Programer(c) is represented by the triple (programmer, c,
dummy_f) and a Mathematician(x) is represented by (mathematician,
dummy_c, f). In a less strictly typed language (e.g. assembler), we may
avoid the redundancy and encode the sum with the product type

  type person'' = int * t

where t is a type large enough to hold both char and float. This is
precisely how people who use "lesser" languages work with sums, and
precisely how sums are represented in compiled ocaml code (modulo
optimizations). Of course, it does not provide a water-tight duality
between products and sums at the level of datatypes, but a certain
realizability construction gets you to a category (built on top of
datatypes) in which the above trick is precisely how sums are
constructed--all that is added as an aftertaught is the definition of
the subobject of person' consisting of those triples whcich represent
valid values of the corresponding sum type.

Andrej


  reply	other threads:[~2006-01-20  9:56 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 [this message]
2006-01-20 18:59                             ` William Lovas
2006-01-20 20:59                               ` skaller
2006-01-21 18:36                                 ` Andrej Bauer
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=43D0B413.1060806@andrej.com \
    --to=andrej.bauer@andrej.com \
    --cc=caml-list@inria.fr \
    --cc=wlovas@stwing.upenn.edu \
    /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).