Template late binding error when specialized.

61 views
Skip to first unread message

aditya siram

unread,
Dec 10, 2017, 3:12:39 PM12/10/17
to ats-lang-users
Hi,
I was following along with the templates as functors part of the tutorial (http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/INT2PROGINATS-BOOK-onechunk.html#templates-as-a-special-form-of-functors) and the provided example works fine, but if I removed all the template arguments and specialized the function arguments to 'int' and change 'list_map_fun' to always increment the int:
extern fun list_map{n:nat} (xs: list(int, n)): list_vt(int, n)
extern fun list_map$fopr(x: int): int
implement list_map
(xs) =
  let
    fun aux
{n:nat}
         
(xs: list(int, n)): list_vt(int, n) =
     
(
       
case+ xs of
       
| list_nil() => list_vt_nil()
       
| list_cons(x, xs) => list_vt_cons(list_map$fopr(x), aux(xs))
     
)
in
  aux
(xs)
end
extern fun list_map_fun{n:nat} (xs: list(int, n)): list_vt(int, n)
implement list_map_fun
(xs) =
let
  implement list_map$fopr
(x) = x + 1
in
  list_map
(xs)
end

Now I get following error on the 'implement list_map$fopr(x) = x + 1' line:
...: the implementation should be at the top-level but it is not.Enter code here...

Does this approach not work when templates have no polymorphic arguments?
Thanks!

Hongwei Xi

unread,
Dec 10, 2017, 3:19:27 PM12/10/17
to ats-lan...@googlegroups.com
It works.

You need '{}' and '<>'

extern fun{} list_map(...): ...

implement list_map<>(...) = ...

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@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/c9cdbd1c-3532-4512-afcf-2acf040cccba%40googlegroups.com.

aditya siram

unread,
Dec 10, 2017, 3:40:34 PM12/10/17
to ats-lang-users
Oh, cool, thanks!

Another thing I just noticed that was a little confusion was that the '$fopr' and '$cont' naming used in the source is just convention, I can change it to anything and still seem to get the same results. Not saying it's a problem, just didn't know.
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.

Hongwei Xi

unread,
Dec 10, 2017, 4:34:54 PM12/10/17
to ats-lan...@googlegroups.com
Right, it is just a convention.

Templates are mostly an experimental feature in ATS.
I find them to be extremely useful, though. There are a lot
of learned lessons on templates that can be readily put into
the next version of ATS, if there is ever going to be one :)


To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.

aditya siram

unread,
Dec 10, 2017, 6:01:18 PM12/10/17
to ats-lang-users
Can you share some of those lessons?

Hongwei Xi

unread,
Dec 10, 2017, 6:18:36 PM12/10/17
to ats-lan...@googlegroups.com
Most of the lessons I had in mind are technical in nature.

For instance, template parameter instantiation is currently done
after type-checking, making it very difficult to mix dependent types
with templates. A related issue is that only types can be template
parameters noe but there are strong cases where one wants integers, for
example. I can go on and on but these things tend to be very technical.


To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages