On Fri, Jul 18, 2003 at 11:39:48AM +1000, Andrew J Bromage wrote:
Someone mentioned multiplying by a scalar. I think this is a good application, but what we need is to agree (somehow) on the symbol used. I've used (*.) and (.*), with the dot being on the side the scalar is on (on the grounds that . is a scalar product elsewhere), but without wide agreement I agree that this sort of thing reduces readability, because while I can read these programmes, it's harder for everyone else.
Yuck. :-)
What's wrong with that solution? You might hope for something better, but it seems like it would work for, e.g., your situation below. Here are my concrete suggestions, using a variant of this notation; however, I mark the side that does _not_ have the scalar, on the grounds that scalar * scalar should be the original operator, and use '*>' or '<*' to do it.
I've run into the same problem with affine algebra, which has two types, the Point and the Vector, where a Vector is the difference between two Points:
Vector + Vector = Vector v1 + v2 = v3 Vector + Point = Point v1 +> p1 = p2 Point + Vector = Point p1 <+ v1 = p2 Point + Point is an error
Vector - Vector = Vector v1 - v2 = v3 Point - Vector = Point p1 <- v1 = p2 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. Point - Point = Vector p1 <-> p2 = v1
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
One solution might be to relax the rules about how the types of operators are resolved. At the moment, you can define function names from different modules and all you need to do is qualify them when you use them. It's a little odd that you can't do something similar with operators, though no succinct syntax leaps to mind.
But you can use qualified names for operators! It just looks incredibly ugly. But you could write, say, 1 Float.+ 2 Peace, Dylan