On Sat, Jul 19, 2003 at 02:06:44PM +1000, Andrew J Bromage wrote: > G'day all. > > On Fri, Jul 18, 2003 at 04:08:25AM -0400, Dylan Thurston wrote: > > > What's wrong with that solution? > > 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. > > For example, using the suggested notation: > > > v1 + v2 = v3 > > v1 +> p1 = p2 > > p1 <+ v1 = p2 > > Quickly, without thinking too much, where do the '<' and '>' signs > go here? > > 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 = p2 > > I'm pretty sure that's a syntax error. If not, it probably should be. Oh, I missed that. Yes. > > > Vector - Point = 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. > > 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 = 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 > > > > class Additive a b c | a b -> c, c a -> b, c b -> a where > > (+) :: a -> b -> c > > class (Additive c b a) => Subtractive a b c where > > (-) :: a -> b -> c > > 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
pgp00000.pgp
Description: PGP signature