[Grace-core] Class syntax and type parameters

Marco Servetto marco.servetto at gmail.com
Fri Nov 14 23:07:45 PST 2014


a polimorphic method is a method that return a different type
depending on the type of the arguments.


By this definition, I don’t think that we have polymorphic methods.

We have methods with type parameters — these return an object with a
type that depends on the value of the type parameter.

Ok, I think there is a little misunderstanding here.
Yes, your definition of "methods with type parameters" is better then
my slopply one and captured what I indented.
In my definition I referred to the value of the argument since I
assumend the generic parametrization inference as in Java/C#/C++. My
bad.
(1)So, Do we need to -at least show- to our beginner student any
"methods with type parameters" ?


----------------

>Sorry, I’ve no idea what this means.   Can you explain it to  me in different words?
(2)
In C++ templates, a template class is a "function at compile time" or
macro, that expand creating a non generic code.
I propose to have a function creating classes, (similar to the
proposal of [] to create types)
so that to use a vector of nat, one have to declare a class named
"VectorOfNat" and then use it. Before typechecking such special
functions would be executed, and the typechecker would typecheck the
resulting "code".

Something like
def NVector as Vector[N]
or class NVector =Vector[N]
or some other graceful syntax.

By following the caching idea of Tim and Michael we could avoid this
"forced typedef", but I personally found it is good to have it.

If such special functions/macros are wrote by us, and not by the
students, we can assume they are well written, so instantiating them
can create no misleading errors.
Otherwise, there are reasonably simple ways to make the generated code
correct by construction, I can expand here if you are interested.



More information about the Grace-core mailing list