[Grace-core] Class syntax and type parameters

Marco Servetto marco.servetto at gmail.com
Mon Nov 17 00:02:52 PST 2014


HI Andrew,
>The third problem is with  Vector and vector.  What are they?
of course they are object, and I do not think my proposal is soo
different w.r.t. the recent one. I actually think their proposal was
sort of born by some of my suggestions.
The main different in my proposal is that I want to "stop there" and
do not have any polymorphism on methods.

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

Umm, is this not already true for the normal class sugar?
if the class is a sugar for an object with a method, is such object
the same or differen w.r.t. the "first class" nominal type value?
if is the same, the same trick should be usable also here.


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

I disagree in two ways:
--If you do not want to teach them to write their own "generic classes"
   you do not need to talk about it at all! you can just say that
Vector is part of the "language"
if I understand correctly, that also what Kim is doing about closures:
at fool he said
that he do not teach such weird part of the language and try to make
the students see "if" as a language constructs. (@kim, is this
correct??)

--If you want them to write their own "generic stuff", then what is simpler?
**code expansion and normal type system, that is, imagine multiple
variation of your code
**f-bounded polimorphism as in java generics.
  How you explain that without asking them to "imagine multiple
variation of your code"

On 17 November 2014 14:34, Andrew P. Black <black at cs.pdx.edu> wrote:
>
> 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
>



More information about the Grace-core mailing list