Template and Overloading

32 views
Skip to first unread message

Steinway Wu

unread,
Aug 12, 2016, 12:13:12 PM8/12/16
to ats-lang-users
Hi, 

Is it possible to do overloadings like below?

```
fun {a:t@ype} gcomapre_val_val (a, a): int

symintr compare
overload compare with gcompare_val_val<int> 
overload compare with gcompare_val_val<uint> 
```

I'm asking this since this. Say, we have a dummy `mycompare`

```
fun {a:t@ype} mycompare (a, a): int
implement {a} mycompare (x, y) = gcompare_val_val<a> (x, y)

symintr comapre
overload compare with mycompare 
```

Then ATS seems to have a hard time figuring out template variables when instantiating. 
Whenever we use `compare`, we have to specify fully what type it is. I'm thinking if

```
overload compare with mycompare<int>
overload compare with mycompare<float>
``` 

could help in any way?

Steinway Wu

unread,
Aug 12, 2016, 1:17:08 PM8/12/16
to ats-lang-users
I saw this, https://bluishcoder.co.nz/2011/10/19/overloading-functions-in-ats.html, which describes the same thing I would like to do. But those examples no longer work.

gmh...@gmail.com

unread,
Aug 12, 2016, 6:09:40 PM8/12/16
to Steinway Wu, ats-lan...@googlegroups.com

Try:


fun{a:t@ype}

mycompare(INV(a), a): int


Sent from my T-Mobile 4G LTE device


------ Original message------

From: Steinway Wu

Date: Fri, Aug 12, 2016 12:13 PM

To: ats-lang-users;

Subject:Template and Overloading


Hi, 

Is it possible to do overloadings like below?

```
fun {a:t@ype} gcomapre_val_val (a, a): int

symintr compare
overload compare with gcompare_val_val<int> 
overload compare with gcompare_val_val<uint> 
```

I'm asking this since this. Say, we have a dummy `mycompare`

```
fun {a:t@ype} mycompare (a, a): int
implement {a} mycompare (x, y) = gcompare_val_val<a> (x, y)

symintr comapre
overload compare with mycompare 
```

Then ATS seems to have a hard time figuring out template variables when instantiating. 
Whenever we use `compare`, we have to specify fully what type it is. I'm thinking if

```
overload compare with mycompare<int>
overload compare with mycompare<float>
``` 

could help in any way?

--
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 https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/246342e5-b458-4e30-ad6b-adad7615e893%40googlegroups.com.

Steinway Wu

unread,
Aug 15, 2016, 10:59:06 AM8/15/16
to ats-lang-users, stein...@gmail.com
Black magic... Why does it work?

gmhwxi

unread,
Aug 15, 2016, 11:00:40 AM8/15/16
to ats-lang-users, stein...@gmail.com
Reply all
Reply to author
Forward
0 new messages