|User defined precedence for user defined operators. firstname.lastname@example.org (glen herrmannsfeldt) (2006-08-14)|
|Re: User defined precedence for user defined operators. email@example.com (Tommy Thorn) (2006-08-15)|
|Re: User defined precedence for user defined operators. DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-08-15)|
|Re: User defined precedence for user defined operators. firstname.lastname@example.org (Marco van de Voort) (2006-08-15)|
|Re: User defined precedence for user defined operators. email@example.com (Michael Tiomkin) (2006-08-15)|
|User defined precedence for user defined operators. firstname.lastname@example.org (Derek M Jones) (2006-08-15)|
|Re: User defined precedence for user defined operators. email@example.com (2006-08-18)|
|From:||Hans-Peter Diettrich <DrDiettrich1@aol.com>|
|Date:||15 Aug 2006 18:53:47 -0400|
|References:||<firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <1hk1yfv.zyn74w12uw4xsNemail@example.com> <44E0B3FF.firstname.lastname@example.org> 06-08-081|
|Posted-Date:||15 Aug 2006 18:53:47 EDT|
glen herrmannsfeldt wrote:
> As far as I know, the languages that allow operator overloading
> use the same precedence in all cases for each operator.
The same precedence, associativity, and other semantics of the
>>Type(a) + Type(b) returns a Type(b)
IMO binary operands will expand to a.<op>(b), with a possible type cast
of b, into an type compatible with a.<op>. But a and b may be swapped as
well, according to the grouping of the operator <op>.
> [I don't think I've ever seen a language where the operator precedence
> depended on the types of the operands, and I hope I never do. -John]
At least not in a language, that allows for user defined and possibly
polymorphic types, whose exact type is unknown at compile time.
There may exist situations, like a multiplication of an vector by a
scalar, where special handling might make sense. Nontheless it also
would make sense, then, to introduce new operators for such operations.
[I don't doubt that it's possible to write a parser with type-dependent
precedence, but if ever there were a feature guaranteed to produce
unreadable code with hard to find bugs, that's it. -John]
Return to the
Search the comp.compilers archives again.