Overload Syntax

77 views
Skip to first unread message

William Blair

unread,
Dec 8, 2013, 9:16:09 PM12/8/13
to ats-lan...@googlegroups.com
When I overload an operator with a function, I can use the following syntax

    symintr .bar

    fun foo_get_bar (foo): bar

    overload .bar with foo_get_bar of 10

What does the "of x" part of the declaration stand for? 

gmhwxi

unread,
Dec 8, 2013, 10:36:41 PM12/8/13
to ats-lan...@googlegroups.com
It is the priority/precedence of this instance of overload.

Say you have

overload .bar with foo1_get_bar (* of 0 *)
overload .bar with foo2_get_bar of 10

In case where a tie needs to be broken between these two, foo2_get_bar
is picked over foo1_get_bar.

gmhwxi

unread,
Dec 8, 2013, 11:02:25 PM12/8/13
to ats-lan...@googlegroups.com
By the way, the dot notation overloading only when the type 'foo' is non-linear.


On Sunday, December 8, 2013 9:16:09 PM UTC-5, William Blair wrote:

Brandon Barker

unread,
Aug 11, 2014, 1:51:52 PM8/11/14
to ats-lan...@googlegroups.com
I've noticed that the linear analogue of " . " seems to be " -> ". Is this just convention though? For instance, if 'a' is an arrayptr, both of these seem to typecheck:

val tmp = a->[0]

val tmp
= (!a).[0]

gmhwxi

unread,
Aug 11, 2014, 8:07:32 PM8/11/14
to ats-lan...@googlegroups.com
The former is a variant of the latter.

Brandon Barker

unread,
Aug 11, 2014, 8:17:11 PM8/11/14
to ats-lang-users
It isn't urgent but I guess I'm not clear on what the above (old comment) means " the dot notation overloading only when the type 'foo' is non-linear", since an arrayptr is linear (and it sill works).

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/6028e39e-9ecf-4d40-97f0-066d3b315312%40googlegroups.com.

gmhwxi

unread,
Aug 11, 2014, 8:27:48 PM8/11/14
to ats-lan...@googlegroups.com

In A.[i], the notation .[i] is considered  a label.

Dot notation overloading means to use dot notation to refer to a function call:

For instance, list_head is a function. If one wants to write xs.head for list_head(xs),
then the following code is needed first:

overload .head with list_head

Dot notation does not work if the argument of the involved function is linear.

Brandon Barker

unread,
Aug 11, 2014, 8:40:04 PM8/11/14
to ats-lang-users
Ah, I think the "dot notation" I was thinking of is different since it is not overloaded in the way you have described (only [] is overloaded not ".[]").

Brandon Barker
brandon...@gmail.com


Yannick Duchêne

unread,
May 19, 2015, 4:15:53 PM5/19/15
to ats-lan...@googlegroups.com
Related, not about syntax, but about when overload is needed.

If I have a praxi with an argument then next after, a fun of the same name without an argument, if I refer to the praxi with an argument, ATS complains about an arity miss‑match. I can solve it either using different name for both, optionally introducing a symbol and overloading it, if I really want to use the same name for both in practice.

I though is was OK to expect the arity is enough to disambiguate, but it seems not and explicit overloading is necessary.
Reply all
Reply to author
Forward
0 new messages