User-Defined Operators, Re: Function composition and currying

Dylan Thurston dpt@math.harvard.edu
Sat, 19 Jul 2003 01:52:32 -0400


--9jxsPFA5p3P2qPhR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jul 19, 2003 at 02:06:44PM +1000, Andrew J Bromage wrote:
> G'day all.
>=20
> On Fri, Jul 18, 2003 at 04:08:25AM -0400, Dylan Thurston wrote:
>=20
> > What's wrong with that solution?
>=20
> Working with these operators, I would spend a significant amount of
> time getting the '<' and '>' notations right rather than writing
> code.  I don't like that.
>=20
> For example, using the suggested notation:
>=20
> >  v1 + v2 =3D v3
> >   v1 +> p1 =3D p2
> >   p1 <+ v1 =3D p2
>=20
> Quickly, without thinking too much, where do the '<' and '>' signs
> go here?
>=20
> 	p1 + v1 + v2
> 	v1 + v2 + p1
> 	v1 + p1 + v2

Easy:

   p1 <+ (v1 + v2) or (p1 <+ v1) <+ v2
   (v1 + v2) +> p1
   v1 +> p1 <+ v2

The parens are slightly annoying (and to drop them I'd have to remember
that the associativity of the operators), but they're mathematically
clear.  It's maybe easiest to think in terms of group theory with an
action on a set: you're just distinguishing between the multiplication
of group elements and the actual action.  This distinction is not
usually reflected in the notation, but it's really not such a hardship.

> >   p1 <- v1 =3D p2
>=20
> I'm pretty sure that's a syntax error.  If not, it probably should be.

Oh, I missed that.  Yes.

> > > 	Vector - Point =3D Point	-- (this rule is a bit controversial)
> > This one is obviously an error.  Add Point to both sides to get the
> > error that you noted above.
>=20
> It depends.  If you allow the parity inversion operator -Point, then
> this operation makes a certain amount of sense.  Some implementations
> (e.g. RenderMan) allow it, some don't.

But if you have -Point, then you have a 0 Point, and there's no
distinction between Points and Vectors at all!

> (But then, RenderMan defines Point + Bivector =3D Point.  Clifford
> algebraists may now run screaming.)

I tried to think about what that should mean, and did not succeed.  What
is this operation?

> > The other potential solution is to use an 'Additive' class
> >=20
> > class Additive a b c | a b -> c, c a -> b, c b -> a where
> >   (+) :: a -> b -> c
> > class (Additive c b a) =3D> Subtractive a b c where
> >   (-) :: a -> b -> c
>=20
> Actually, that's not bad at all.  It's certainly better than my
> previous suggestion of only putting a b -> c on "Additive" typeclass.

As I recall, the extra functional dependencies don't help very much in
practice with the ambiguities previously noted.  But you should try it
for yourself.

Peace,
	Dylan

--9jxsPFA5p3P2qPhR
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/GNygVeybfhaa3tcRAmcoAJ4kVzdCPLl9K3iK8SuZCnEgZgAoMQCdF1oq
Kp3700e3ur/sI+IatUR+PPI=
=tsME
-----END PGP SIGNATURE-----

--9jxsPFA5p3P2qPhR--