Operator overloading?

98 views
Skip to first unread message

杨博

unread,
Jan 8, 2013, 10:21:23 AM1/8/13
to haxe...@googlegroups.com
Hello, everyone. I am glad to anounce my library Hoo, which enables operator overloading for Haxe.

My first intention is enable better syntax for Int64, like this:
var i64 = Int64.ofInt(1234567890);

// Output: 123456789000054321
trace(Int64.toStr(i64 * 100000000 + 54321));
After doing some work, it does work. And I found the way I use for Int64 is suitable for more purpose. Anybody interesting?

Simon Krajewski

unread,
Jan 8, 2013, 10:57:07 AM1/8/13
to haxe...@googlegroups.com
Am 08.01.2013 16:21, schrieb 杨博:
Hello, everyone. I am glad to anounce my library Hoo, which enables operator overloading for Haxe.

Very nice! I like the using-based solution, it nicely takes care of the selection this way.

Simon

杨博

unread,
Jan 8, 2013, 11:10:01 AM1/8/13
to haxe...@googlegroups.com
Thanks. BTW: I use a selector as the first parameter for evaluate, not just the left operand of the operator. That's because sometimes I need to choose overloaded function by the right operand. e.g. 123+Int64.ofInt(123)

在 2013年1月8日星期二UTC+8下午11时57分07秒,Simon Krajewski写道:

Simon Krajewski

unread,
Jan 8, 2013, 11:13:57 AM1/8/13
to haxe...@googlegroups.com
Am 08.01.2013 17:10, schrieb 锟筋博:
Thanks. BTW: I use a selector as the first parameter for evaluate, not just the left operand of the operator. That's because sometimes I need to choose overloaded function by the right operand. e.g. 123+Int64.ofInt(123)

I saw, and it's the right thing to do. Did you try allowing EArray as pseudo-operator?

Simon

杨博

unread,
Jan 8, 2013, 11:21:24 AM1/8/13
to haxe...@googlegroups.com
Not yet. Could provide a patch for the feature?

在 2013年1月9日星期三UTC+8上午12时13分57秒,Simon Krajewski写道:

Jason O'Neil

unread,
Jan 9, 2013, 12:31:28 AM1/9/13
to haxe...@googlegroups.com
Really nice library...

I'm always impressed with your use of macros :)


Luca

unread,
Jan 9, 2013, 8:28:00 PM1/9/13
to haxe...@googlegroups.com
Would it be possible to program optimisations into this too?

for instance should you overload + and * for vector types like:

(+) a b => new Point(a.x+b.x, a.y+b.y);
(*) a x => new Point(a.x * x, a.y * x);

you might want to have: (a + b) * x to be converted to new Point((a.x+b.x)*x, (a.y+b.y)*x) instead


杨博

unread,
Jan 10, 2013, 12:07:10 AM1/10/13
to haxe...@googlegroups.com
Yes! You can implement evaluate as macro function, which produce optimise code if the parameter expressions is ENew.

在 2013年1月10日星期四UTC+8上午9时28分00秒,Luca写道:
Reply all
Reply to author
Forward
0 new messages