Static Templates

70 views
Skip to first unread message

Steinway Wu

unread,
Oct 20, 2017, 5:45:45 PM10/20/17
to ats-lang-users
Hi, 

We now have dynamic templates, parameterized by static terms. Is it possible to have some simple form of static templates like the followings? Or is there any other way to make static functions ad-hoc polymorphic? 

datasort typelist =
| tnil of ()
| tcons of (t@ype, typelist)

#define :: tcons

datatype
OneConstructor     = One     of (int, int, string)
datatype
AnotherConstructor = Another of (int, int, bool)

template stacst Code<type>: typelist

implement
Code<OneConstructor>     = int :: int :: string :: tnil
implement
Code<AnotherConstructor> = int :: int :: bool :: tnil






gmhwxi

unread,
Oct 21, 2017, 4:26:02 PM10/21/17
to ats-lang-users
I don't know how to do it,

This gets into the domain of meta-programming.

In general, it is very difficult to do meta-programming in a typeful
manner.  Often one tries to write code to generate code that may
contain type-error and then apply typechecking to the generated code.

Steinway Wu

unread,
Oct 22, 2017, 2:52:08 PM10/22/17
to ats-lang-users
I was trying to add some "derive" functionality by representing datatypes, say "a" with some generic datatype, say "rep (a)". However, for a generic function to work on a value of type "rep (a)", we need the type information for the actual values stored in the original value of type "a" (which are copied into the value of type "rep (a)"). 

It's much like trying to print a heterogeneous list, generically. I need to supply the print function with the actual type of every element. Thus I think I probably need the type info to be a template, so that the user can instantiate it for every datatype they want to be generic. 

Am I on the right track? Are there other ways of doing it? 
Reply all
Reply to author
Forward
0 new messages