Thanks for clarifying.
In your example, there are three templates named g_print.
In particular, the types/interfaces of these three templates do
not have to be the instantiation of one general type/interface.
In ATS, we have one g_print:
fun<a:type> g_print(x: a): void
And then three implementations:
impltmp g_print<int> = ...
impltmp g_print<string> = ...
impltmp{a:type} g_print<list(a)> = ...
This subtle difference affects how type-checking is performed.
In C++, template instantiation/resolution is done first and then
type-checking is performed on the result
of instantiation/resolution.
In ATS, ML-like algebraic type-checking is done before template resolution.
And linear and dependent
type-checking on the result of template resolution is planned to be done
after.
On Fri, Jul 3, 2020 at 7:55 AM Chris Double <[email protected]>
wrote:
> On Fri, Jul 3, 2020 at 6:46 PM gmhwxi <[email protected]> wrote:
> >
> > Did I miss something about C++ templates? It seems that the template
> parameters
> > of a template implementation in C++ must be variables.
>
> I think this C++ example does what you are trying, unless I'm
> misunderstanding the ATS code:
>
> --------------------------8<----------------------
> #include <iostream>
> #include <list>
>
> template <class T> void g_print(T const& x) {
> std::cout << "case 1" << std::endl;
> }
>
> template <> void g_print(int const& x) {
> std::cout << "case 2" << std::endl;
> }
>
> template <class T> void g_print(std::list<T> const& x) {
> std:: cout << "case 3" << std::endl;
> }
>
> int main() {
> g_print("hello");
> g_print(5);
> std::list<int> l;
> g_print(l);
> return 0;
> }
> --------------------------8<----------------------
>
> It prints out:
>
> case 1
> case 2
> case 3
>
> Chris.
> --
> https://bluishcoder.co.nz
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CALn1vHEpfccad3EydBsRjLsoxWo%3DgBgUGQVfD-naT9BYqTeqOQ%40mail.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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpBhXx%3DvaySfrkZSuoF4KfS5zL--sjzgEMX59UkCVczqQ%40mail.gmail.com.