POSSREPs as union types

From: Marshall <marshall.spight_at_gmail.com>
Date: Sat, 29 Aug 2009 23:07:33 -0700 (PDT)
Message-ID: <2942b968-577d-494c-bb77-f3d6ffb62b65_at_x25g2000prf.googlegroups.com>



I had a though about possreps the other day, and I wanted to post it, for no particular reason. This thought is not much developed, so don't expect much. :-)

It occurred to me that possreps have a lot in common with union types. Briefly, a disjoint union is a language construct that permits a type to consist of disjoint sets of values, each disjoint set having its own named constructor and constructor arguments.

For example, one could define a binary tree of ints as follows:

  type tree = leaf int | branch tree tree;

Meaning a tree is either a leaf with an associated int, or a branch with a left (sub)tree and right (sub)tree.

Suppose one were to give names to the attributes of the constructors:

  type tree = leaf value:int | branch left:tree right:tree;

No big deal.

Suppose I use the classic possrep example, a point with polar or rectangular coordinates.

  type point = polar r:real theta:real | rectangular x:real y:real;

Now suppose I add to the type enough information to describe the bijection between the two constructors:

  type point = polar r:real theta:real | rectangular x:real y:real

      where
         x = r * cos(theta),
         y = r * sin(theta);

(Please allow me to be all handwavey about the r=0 case
so as to focus on the big picture.)

I think that's roughly enough information to be able to do all the necessary work.

This makes possreps and union types look quite similar to me. It also gives a clear idea of how to differentiate between "member functions" that ought to belong
("directly" if you will) to the type, and those that are
less immediately associated: whether or not they are constructor arguments.

Is it necessary that there always be a bijection between multiple possreps for a type? If not, how does one convert between them?

Marshall Received on Sun Aug 30 2009 - 08:07:33 CEST

Original text of this message