[Grace-core] Class syntax and type parameters

Andrew P. Black black at cs.pdx.edu
Sun Nov 16 23:34:32 PST 2014


On 14 Nov 2014, at 23:07, Marco Servetto <marco.servetto at gmail.com> wrote:

> 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.

I see three problems with this proposal.  The first is that it requires the instructor to talk about “compile time” and “functions”, along with “code expansion”. 
None of these is a concepts that I want to introduce to novices.

The second problem is that it gives up on referential transparency.   You propose that we write (something like)

	type NVector = Vector[N]
	class nVector = vector[N]

but then that NVector and Vector[N] are not equal, that is, I can’t substitute one for the other.  

Now, I agree that we already don’t have referential transparency where variables are concerned, but in the declarative sub-lanuage of types, we do have it, and I would rather like to keep it.   I don’t know how to do type checking otherwise.

The third problem is with  Vector and vector.  What are they?  Are Vector and vector objects, or not?   If they are objects, how is this different from what Michael and Tim recently proposed?   And if they are not objects, then what are they?  One more new thing to tell the novices about?

	Andrew
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20141116/2614aa9b/attachment.html>


More information about the Grace-core mailing list