Reimplementing the bulk of std.meta iteratively

Timon Gehr timon.gehr at gmx.ch
Thu Oct 1 07:48:52 UTC 2020


On 01.10.20 04:49, Stefan Koch wrote:
> On Wednesday, 30 September 2020 at 23:17:27 UTC, Timon Gehr wrote:
>> On 29.09.20 01:37, Stefan Koch wrote:
>>> On Monday, 28 September 2020 at 21:27:56 UTC, Timon Gehr wrote:
>>>> On 28.09.20 23:08, claptrap wrote:
>>>>> Instead of first class types
>>>>
>>>> (Stefan's type functions do not give you first-class types. A 
>>>> first-class type you could put in a runtime variable.)
>>>
>>> That's true. At least as it stands right now.
>>> I _could_ give  the alias a physical form at runtime.
>>> (By doing the same thing that the reify template does (or rather will 
>>> eventually do), that is exporting _all_ the properties of the type 
>>> into an object)
>>>
>>> However I am not actually sure what the use of this would be.
>>> All usage that I have seen, is in generating code, which is kindof 
>>> useless if it does not happen at compile time.
>>>
>>> Perhaps there are others?
>>
>> It's not a first-class type if you can't declare a variable of that 
>> type. If this does not work, it's not first-class, it's syntax sugar 
>> for reification:
>>
>> type t = int;
>> auto f = (t x)=>x;
> 
> Yes I do understand that.
> I was wondering about practical usecases.
> As far as I an aware, if I made the leap to first class types, that 
> would make all usage of them into static polymorphism. (equivalent to 
> templates)
> And with that all the issues come back.

Well, no, the restriction to compile-time-known values makes types not 
first-class. E.g., this is something you could do with first-class types 
but not with templates: (type T)=>(T x)=>x;

(In terms of compiler implementation, the runtime representation of `T` 
would contain all information that is necessary to figure out calling 
conventions of functions that take a T, it would contain sizeof, 
pointers to destructor/postblit, etc, so basically it's typeid.)

Templates are an untyped macro language on top of a simple type system 
without any form of polymorphism. Types are first-class values only 
inside that macro language, but the macro language is evaluated only at 
compile time. I.e., templates are a tool for code generation that is 
integrated with the type system, but they are not really a part of the 
type system.


More information about the Digitalmars-d mailing list