Thread overview
Algebraic and implicit conversions
Jan 06, 2020
Per Nordlöw
Jan 06, 2020
drug
Jan 06, 2020
drug
January 06, 2020
Is there a reason why

    alias A = Algebraic!(long, string);
    A x;
    x = 42;

doesn't implicitly convert `42` to `long` and stores it in `x`?
January 06, 2020
06.01.2020 20:08, Per Nordlöw пишет:
> alias A = Algebraic!(long, string);
>      A x;
>      x = 42;

That's because you try to assign int, not long. This works:

alias A = Algebraic!(long, string);
A x;
x = 42L;
January 06, 2020
On 1/6/20 2:33 PM, drug wrote:
> 06.01.2020 20:08, Per Nordlöw пишет:
>> alias A = Algebraic!(long, string);
>>      A x;
>>      x = 42;
> 
> That's because you try to assign int, not long. This works:
> 
> alias A = Algebraic!(long, string);
> A x;
> x = 42L;

I think his question is, why shouldn't this work? e.g., this works:

long x;
x = 42;

FWIW, 3rd-party algebraic types (e.g. TaggedAlgebraic) will do a conversion for this.

-Steve
January 06, 2020
06.01.2020 22:48, Steven Schveighoffer пишет:
> 
> I think his question is, why shouldn't this work? e.g., this works:
> 

Ah, indeed. Sorry for noise.