What type functions mean on a language level
Max Haughton
maxhaton at gmail.com
Wed Jan 13 20:41:38 UTC 2021
On Wednesday, 13 January 2021 at 17:09:59 UTC, Stefan Koch wrote:
> On Tuesday, 12 January 2021 at 20:41:02 UTC, Q. Schroll wrote:
>> On Wednesday, 6 January 2021 at 13:52:39 UTC, sighoya wrote:
>>> If we allow a __type__ in type position, indirectly or
>>> directly, we're able to implement generics known from other
>>> languages, e.g.:
>>>
>>> ```
>>> method(__type__ type)(type value){...}
>>> ```
>>> vs
>>>
>>> ```
>>> method(T)(T value){...}
>>> ```
>>
>> Is this a suggestion or what you think the semantics'
>> consequences are? Because I fail to see how the first one is
>> any different from a template. If I replace `__type__ type` by
>> `int i`, it is still a compile-time argument. In one instance,
>> the value argument is (or represents) a type. That doesn't
>> change the semantics, or does it?
>
> A value type can only be used as type if it a statically known
> value,
> which in the above example is the case.
> But I doubt it will work with the ITFI functionality as it is
> currently implemented.
>
> I have never intended this usecase, I think that we should be
> able to get it to work,
> but I am not sure if that's the most productive thing to do.
I think the usefulness of typefunctions will derive from treating
them as an instance of some type like any other. __type__ is
conceptually equivalent to having some string mixin of the type
it represents. Maybe you shouldn't do so, but a __type__ in a
template is just any other template argument - it shouldn't be
rewritten to anything else.
Stefan, I'm thinking of writing a short document (DIP-lite) to
document where I think typefunctions should be specified and
used, maybe you could look over it?
More information about the Digitalmars-d
mailing list