The "type" type dream

Stewart Gordon smjg_1998 at yahoo.com
Wed Nov 26 14:49:45 PST 2008


"Michel Fortin" <michel.fortin at michelf.com> wrote in message 
news:gghpq4$2nc6$1 at digitalmars.com...
<snip>
> Here, valueTypeOf is a function taking a type as argument and returning 
> another type. Obviously, it's a function that can only be evaluated at 
> compile-time, but with it we can just forget about using templates and 
> declarative programming when we need to create variables of related types.

If it can only be evaluated at compile-time, ISTM it isn't really types 
being first-class values.  Your idea is an attempt to capture the power of 
templates without using templates, whereas a real system of types as 
first-class values would be more powerful than this.

> [exit dream mode]
>
> Not sure what all this would entail, but if we could return types from 
> functions, would we still need templates at all? Couldn't we just create 
> any struct or class inside the function and return that?
<snip>

We might no longer need templates for functions or type aliases, but I think 
that we would still need class/struct templates.  You could invent a 
notation to construct a class or struct within a function, but I'm not sure 
that you can make it look as nice as the template notation we already have.

Whether you want types to be full first-class values manipulable at runtime 
or merely entities that you can manipulate using CTFE, one implication is 
that type syntax and expression syntax would merge into one common syntax. 
This might make parsing simpler, but you would have to work out how to deal 
with such funny things as that * is postfix for types and prefix for 
expressions, but [] is postfix for both.

I thought a while back about the possibility of giving types first-class 
citizenship.  I suppose that what it really means is that a type used as an 
expression would become the TypeInfo for that type.  But the TypeInfo 
classes probably ought to have more human-readable names - Type, ArrayType, 
ClassType, AAType, etc.  And some properties specific to each of these, e.g. 
valueType for ArrayType and AAType, eliminating the need for the valueTypeOf 
function you proposed.

Hmm....

Stewart.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies
on the 'group where everybody may benefit.




More information about the Digitalmars-d mailing list