Ticket #70 (new enhancement)

Opened 10 years ago

Last modified 10 years ago

Declare operator overloads.

Reported by: Chuck Owned by:
Priority: major Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:


Declare operator overloads for your own classes.

Probably makes sense to do ticket:69 (consume operator overloads) first.

Also, I haven't designed a syntax for this. And it probably makes sense to review operator overloading in various languages such as C#, Python and C++. I think Java is still lacking in this area.

Change History

Changed 10 years ago by Chuck

Also, Cobra already supports a .compareTo instance method for covering all 6 comparison operators (==, <>, <=, etc.).

And one person has effectively suggested going this route by asking if the Scala approach could be used. See

This could also tie into the cue idea.

Changed 10 years ago by Chuck

Cues may be the way to declare operator overloads. Of course, this still has to mesh well with .NET (and any JVM conventions adopted by 3rd party languages).

There is a user proposal here:

Changed 10 years ago by gauthier

I would prefer op or operator keyword rather than cue

class Foo


def +operator (other as Foo) as Foo


def +op (other as Foo) as Foo

Changed 10 years ago by Chuck

If we had a keyword, why wouldn't it replace def as in:

op + (other Foo) as Foo

Having both def and op|operator seems strange.

Note: See TracTickets for help on using tickets.