Overloading Operators

55 views
Skip to first unread message

Steinway Wu

unread,
Aug 6, 2014, 1:41:29 PM8/6/14
to ats-lan...@googlegroups.com
Hi, 

When I try to overload || with some_function, it says the || is not a symbol. Any idea?

Also, is it possible to overload + to be a unary postfix operator?

Thanks,

Brandon Barker

unread,
Aug 6, 2014, 1:56:58 PM8/6/14
to ats-lang-users
This may not be the solution you are looking for, but in ATS contrib, the file ./contrib/libfloats/TEST/test_LAgmat.dats has a macdef (the first one) that allows ^t to work as a postfix transpose operator.

Brandon Barker
brandon...@gmail.com


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/cb04c44d-6fc2-4e8a-a8e5-78701b6c7e57%40googlegroups.com.

gmhwxi

unread,
Aug 6, 2014, 2:05:28 PM8/6/14
to ats-lan...@googlegroups.com
Only functions can be overloaded.

|| and && are already declared as macros in prelude/SATS/bool.sats, so
they cannot be overloaded. However, if you do

symintr &&
overload
&& with <some-function>

Then it works. But after this, && no longer refers to the original macro definition.

+ is current an infix operator. You need to do:

postfix +
overload
+ with <some-function>

Yannick Duchêne

unread,
Aug 6, 2014, 2:47:22 PM8/6/14
to ats-lan...@googlegroups.com


Le mercredi 6 août 2014 20:05:28 UTC+2, gmhwxi a écrit :
Only functions can be overloaded.

But the function an operator symbol designates, may a polymorphic function… or it does work with polymorphic functions?

That's not the same as full overloading, this is just I feel this question is worth to be asked.

Yannick Duchêne

unread,
Aug 6, 2014, 2:48:46 PM8/6/14
to ats-lan...@googlegroups.com


Le mercredi 6 août 2014 20:47:22 UTC+2, Yannick Duchêne a écrit :

But the function an operator symbol designates, may a polymorphic function… or it does work with polymorphic functions?

Sorry, typo. Please, read: “or it does *not* work with polymorphic functions?” 

gmhwxi

unread,
Aug 6, 2014, 2:59:56 PM8/6/14
to ats-lan...@googlegroups.com
Yes, polymorphic functions can be overloaded.
Also, function templates can be overloaded as well.

Steinway Wu

unread,
Aug 7, 2014, 4:36:19 PM8/7/14
to ats-lan...@googlegroups.com
Thanks! Although I don't think that's feasible since it overrides the logical operator. But this is a very clear answer.

Yannick Duchêne

unread,
May 10, 2015, 10:40:48 PM5/10/15
to ats-lan...@googlegroups.com
What is the difference between this

infixl 10 +
overload
+ with foo

and this

infixl +
overload
+ with foo of 10

?

Do the `10` stands for the same precedence or do both means something different?


Le mercredi 6 août 2014 20:05:28 UTC+2, gmhwxi a écrit :

gmhwxi

unread,
May 10, 2015, 10:51:29 PM5/10/15
to ats-lan...@googlegroups.com

>> infixl 10 +

10 is the precedence of '+'.

Suppose you have an expression '1 + 2 ++ 3';
if ++ has a higher precedence, then the expression
is parsed as 1 + (2 ++ 3); if ++ has a lower precedence,
you get (1 + 2) ++ 3.

>>
overload + with foo of 10

Say you also have:

overload + with foo2 of 11

Suppose you have (x + y); if (x + y) can be translated to both foo(x, y) and foo2(x, y),
the foo2 is chosen (as it has a higher overloading value than foo).

Reply all
Reply to author
Forward
0 new messages