[Python-ideas] Is there a good reason to use * for multiplication?

Masklinn masklinn at masklinn.net
Sat Oct 13 11:32:24 CEST 2012


On 2012-10-13, at 10:18 , Steven D'Aprano wrote:
>> Perhaps instead I would like it if all operators were objects with e.g.
>> special __infix__ methods.
> 
> I believe that Haskell treats operators as if they were function objects

That is correct for binary operators. The unary minus is (currently) a
keyword and sugar for the negate function[0].

So `map (-) values` is not going to negate all values, it's going to
partially apply the binary `(-)` to all values.

> but I think that puts the emphasis on the wrong thing.

I'm not sure I understand that, what does it put the emphasis on? Note
that these operators — when generic — tend to live in typeclasses, so
the actual implementation of the behavior of the operator for the set
of its arguments is defined where and when the corresponding typeclass
instance is created. This is essentially how Python's own operators
(and some builtins e.g. ``divmod`` or ``pow``) work (except Haskell
doesn't have a reflected operands fallback)

[0] http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:negate




More information about the Python-ideas mailing list