First life-signs of type functions
Stefan Koch
uplink.coder at googlemail.com
Tue May 12 19:43:13 UTC 2020
On Tuesday, 12 May 2020 at 19:15:54 UTC, Steven Schveighoffer
wrote:
> On 5/12/20 1:32 PM, Johannes Loher wrote:
>> On Tuesday, 12 May 2020 at 16:12:42 UTC, Steven Schveighoffer
>> wrote:
>>> I can totally envision this pattern happening:
>>>
>>> string foo(string[] symbolnames, alias dummy = __dummy)
>>> {
>>> // do something with symbolnames, ignore dummy
>>> }
>>>
>>> to force a type function instead of using CTFE when you want
>>> to manipulate a compile-time list of strings.
>>>
>>
>> Why would you ever do this? To enforce that the function is
>> only called at compile time?
>
> I'm assuming in type functions we have further leeways that
> aren't available in CTFE functions. Like, for instance,
> SomeTemplate!(symbolnames[0]) should be doable in a type
> function, but would not be doable in a CTFE function.
>
> Not sure if that would require symbolnames be an alias[] or not.
>
>> Looks like a hack to a problem we should have a proper
>> solution for instead.
>
> I agree, which is why I brought it up.
>
> -Steve
Actually no.
If you did that you would be passing a variable to a template
which expects a type.
Type functions are not magic and they are not dynamically typed.
Their purpose is to offer an alternative for introspection
usecases.
In which the genericty of templates is not needed and the
compiler is unwanted.
There no way to make a type out of a type variable.
Because that would require a dynamic type system.
Type functions provide a compile time interface to introspection
abilities without incurring the cost of templates, and providing
the option to write code in imperative programming style.
@johannes I have put some thought into how this will interact and
so far the simplicity of the implementation seems to point
towards very nice interplay as well.
When there is more of a full featured implementation I will
present a more formal discussion about the topic.
More information about the Digitalmars-d
mailing list