Introduction to function templates

66 views
Skip to first unread message

gmhwxi

unread,
Mar 8, 2015, 2:06:57 PM3/8/15
to ats-lan...@googlegroups.com

I added a chapter on function templates in my Intro-to-ATS book:

http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/

This chapter is in Part V of the book, and it is still being worked. However, it can
already provide a lot of useful information on function templates in ATS. Cheers!

Brandon Barker

unread,
Mar 8, 2015, 2:10:59 PM3/8/15
to ats-lang-users
The long awaited chapter :). Looking forward to it

--
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/85e05133-4905-40e9-90af-8a2a4b57d05a%40googlegroups.com.



--
Brandon Barker
brandon...@gmail.com

Artyom Shalkhakov

unread,
Mar 10, 2015, 10:26:04 AM3/10/15
to ats-lan...@googlegroups.com

Great work!

I have a question: why do you use list0 in the myprint example? Why not use an existentially quantified List instead?

Also, and more importantly, when is it necessary to fully apply type parameters to a function template? And when is it OK to omit them?

Shea Levy

unread,
Mar 10, 2015, 10:50:13 AM3/10/15
to ats-lan...@googlegroups.com
Very cool! One question: If templates follow a first-fit model, why do you define the specialization partial order? Is it used for anything?

gmhwxi

unread,
Mar 10, 2015, 10:34:35 PM3/10/15
to ats-lan...@googlegroups.com

The template parameters of a template implementation were not allowed to
be quantifed types. After thinking over the issue today, I slightly modified the
method used to locate the template implementation for a template instance.
Now you can do

implement(a)
myprint
<List(a)> (xs) = ...

val
() = myprint<List(int)> (...)


Because locating the template implementation for a template instance is done
*after* the erasure of type indices, the template parameter matching must be exact.
For instance,

implement(a)
myprint
<list(a,2)> (xs) = ...

val
() = myprint<list(int, 1+1)> (...)


There is NO match here because 1+1 and 2 are *syntactically* different.

gmhwxi

unread,
Mar 10, 2015, 10:42:28 PM3/10/15
to ats-lan...@googlegroups.com

The partial order is a concept.
It just happens that it is not used in the current implementation.

It could be useful if one wants to report a warning in a case where
first-fit is not the same as best-fit.

Shivkumar Chandrasekaran

unread,
Mar 13, 2015, 9:55:31 AM3/13/15
to ats-lan...@googlegroups.com
Hi Hongwei,

I think this is a brilliant feature. I feel it would be even nicer to pass the needed templates explicitly as arguments; may be <<.>>. Otherwise the search strategy reminds me of metaCLOS!

Best.

--shiv--

gmhwxi

unread,
Mar 13, 2015, 11:57:54 PM3/13/15
to ats-lan...@googlegroups.com
Thanks!

Putting the current design of templates into ATS2 was a big gamble on my part.
I now do feel a lot of comfortable about the design than I did two years ago, when the
design was largely untested. Before that, I spent at least 3 years trying to figure out
how to support OOP in ATS2, which led to a design I eventually abandoned due to its
immense complexity. But I would still like to have some form of OOP :)

To properly indicate which template parameters must be provided is challenging. I will
study the issue more.
Reply all
Reply to author
Forward
0 new messages