TypeFunction example creatiing a conversion matrix
Steven Schveighoffer
schveiguy at gmail.com
Thu Oct 1 16:12:29 UTC 2020
On 10/1/20 9:53 AM, H. S. Teoh wrote:
> On Thu, Oct 01, 2020 at 12:27:23PM +0000, Stefan Koch via Digitalmars-d wrote:
> [...]
>> type functions do a Type -> TypeObject conversion when you pass the
>> types in.
>> inside the type function you get a "type-like" interface.
>> But it has lost everything that made it a type.
>> It has sizeof, alignof, stringof, tupleof, you can use __traits on it.
>> But it cannot be used as a type anymore.
>> Not inside a type-function anyway.
>>
>> If you return a type or a type tuple from a type function, it becomes
>> a regular type/type tuple again.
>
> Isn't this just the same thing as Andrei's reification / dereification,
> except redressed in terms of aliases?
The difference I see is that reification/dereification has to rebuild
everything that is already in the compiler, but at runtime. And it has
to make sure the functionality is identical. You are using the compiler
to build another type introspection system, but just so you can do CTFE
based things.
It reminds me of "modern" web applications which take over browser
functionality (page navigation, etc.) and reimplement it in javascript.
If we can't get a system that allows dereifcation DURING function
execution, then I think type functions are a much better solution.
There's no reason to reimplement what the compiler already does. Type
functions are cleaner, clearer, and much more efficient.
-Steve
More information about the Digitalmars-d
mailing list