March 19, 2021
On Friday, 19 March 2021 at 01:31:59 UTC, Paul Backus wrote:
> On Thursday, 18 March 2021 at 18:42:32 UTC, Oleg B wrote:
>>
>> but read-only tag (kind, type index) is key feature in chouse between sumtype and other for me, and I hope it will be added before next compiler release...
>
> https://github.com/pbackus/sumtype/pull/57
> https://github.com/dlang/phobos/pull/7886

Thank you very much!
March 22, 2021
On Thursday, 18 March 2021 at 14:42:03 UTC, Oleg B wrote:
> Hello everyone.
>
> Went to see what is being prepared in the new compiler and saw this
> https://dlang.org/changelog/pending.html#std-sumtype

Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:

Temperature t1 = Fahrenheit(98.6);
isFahrenheit(t1); // works
isFahrenheit(Fahrenheit(98.6)); // doesn't work :(
March 22, 2021
On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
> On Thursday, 18 March 2021 at 14:42:03 UTC, Oleg B wrote:
>> Hello everyone.
>>
>> Went to see what is being prepared in the new compiler and saw this
>> https://dlang.org/changelog/pending.html#std-sumtype
>
> Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:
>
> Temperature t1 = Fahrenheit(98.6);
> isFahrenheit(t1); // works
> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(

Not that it really makes sense, but if you wanted to do that you could cast:

isFahrenheit(cast(Temperature)Fahrenheit(98.6)) //works

Otherwize you would have to rewrite isFahrenheit
March 22, 2021
On Monday, 22 March 2021 at 20:43:12 UTC, Imperatorn wrote:
> On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
>> On Thursday, 18 March 2021 at 14:42:03 UTC, Oleg B wrote:
>>> Hello everyone.
>>>
>>> Went to see what is being prepared in the new compiler and saw this
>>> https://dlang.org/changelog/pending.html#std-sumtype
>>
>> Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:
>>
>> Temperature t1 = Fahrenheit(98.6);
>> isFahrenheit(t1); // works
>> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(
>
> Not that it really makes sense, but if you wanted to do that you could cast:
>
> isFahrenheit(cast(Temperature)Fahrenheit(98.6)) //works
>
> Otherwize you would have to rewrite isFahrenheit

isFahrenheit(Temperature(Fahrenheit(98.6)))

works too. but that's still extra typing.
March 22, 2021
On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
> Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:
>
> Temperature t1 = Fahrenheit(98.6);
> isFahrenheit(t1); // works
> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(

You can do this by adding an additional overload to isFahrenheit:

bool isFahrenheit(T)(T t)
    if (staticIndexOf!(T, Temperature.Types) >= 0)
{
    return is(T == Fahrenheit);
}

bool isFahrenheit(Temperature temp)
{
    // Forward to template overload
    return temp.match!isFahrenheit;
}
March 22, 2021
On Monday, 22 March 2021 at 21:43:58 UTC, Paul Backus wrote:
> On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
>> Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:
>>
>> Temperature t1 = Fahrenheit(98.6);
>> isFahrenheit(t1); // works
>> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(
>
> You can do this by adding an additional overload to isFahrenheit:
>
> bool isFahrenheit(T)(T t)
>     if (staticIndexOf!(T, Temperature.Types) >= 0)
> {
>     return is(T == Fahrenheit);
> }
>
> bool isFahrenheit(Temperature temp)
> {
>     // Forward to template overload
>     return temp.match!isFahrenheit;
> }

What about something like
Fahrenheit t2 = t1.to!(BaseTypeOf!(typeof(t1)));
that could then be put into its own function.
March 22, 2021
On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
> On Thursday, 18 March 2021 at 14:42:03 UTC, Oleg B wrote:
>> Hello everyone.
>>
>> Went to see what is being prepared in the new compiler and saw this
>> https://dlang.org/changelog/pending.html#std-sumtype
>
> Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:
>
> Temperature t1 = Fahrenheit(98.6);
> isFahrenheit(t1); // works
> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(

I would love this too, but Walter is very against implicit conversions. IMO this is one of the major reasons that algebraic types as a library are not adequate compared to a built-in language feature in D.
March 22, 2021
On Monday, 22 March 2021 at 22:03:07 UTC, jmh530 wrote:
> On Monday, 22 March 2021 at 21:43:58 UTC, Paul Backus wrote:
>> On Monday, 22 March 2021 at 19:24:54 UTC, JN wrote:
>>> Does anyone know if it would be possible to make it support (it doesn't support it now) this kind of syntax:
>>>
>>> Temperature t1 = Fahrenheit(98.6);
>>> isFahrenheit(t1); // works
>>> isFahrenheit(Fahrenheit(98.6)); // doesn't work :(
>>
>> You can do this by adding an additional overload to isFahrenheit:
>>
>> bool isFahrenheit(T)(T t)
>>     if (staticIndexOf!(T, Temperature.Types) >= 0)
>> {
>>     return is(T == Fahrenheit);
>> }
>>
>> bool isFahrenheit(Temperature temp)
>> {
>>     // Forward to template overload
>>     return temp.match!isFahrenheit;
>> }
>
> What about something like
> Fahrenheit t2 = t1.to!(BaseTypeOf!(typeof(t1)));
> that could then be put into its own function.

Not sure what `BaseTypeOf` is supposed to do here, but if you want to extract a particular type from a SumType it's pretty easy:

Target to(Target, Source)(Source source)
    if (isSumType!Source && staticIndexOf!(Target, Source.Types) >= 0)
{
    // Will throw MatchException if the wrong type is found
    return source.tryMatch!((Target target) => target));
}
March 23, 2021
On Monday, 22 March 2021 at 23:25:07 UTC, Paul Backus wrote:
> [snip]
>
> Not sure what `BaseTypeOf` is supposed to do here, but if you want to extract a particular type from a SumType it's pretty easy:
>
> Target to(Target, Source)(Source source)
>     if (isSumType!Source && staticIndexOf!(Target, Source.Types) >= 0)
> {
>     // Will throw MatchException if the wrong type is found
>     return source.tryMatch!((Target target) => target));
> }

I was BaseTypeofOf!Temperature would be returning Fahrenheit in that case. But yes, this looks like it would do what I was thinking.
March 23, 2021
On Thursday, 18 March 2021 at 18:40:49 UTC, ryuukk_ wrote:
> On Thursday, 18 March 2021 at 18:15:29 UTC, Paul Backus wrote:
>>[...]
>
> The syntax is a result of it not being a language feature (the lib itself is perfectly fine, don't get me wrong! but the problem i have is it'd be better as a language feature)
>
> I'd love to help create a DIP for it, but making it as a lib now, and then removing it few months/year later will feel bad because that's gonna be code people will have to change, again, hence the importance of not taking shortcuts, we need think long term

Instead of spending three years on the DIP, start small and spend three days and see how far you come.