Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread sighoya via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 19:38:55 UTC, Paul Backus wrote: That's what Variant is--a struct that models the universal supertype (sometimes called "Top" or "Any"). Ahh right. Good point, so it already fits.

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 18:09:08 UTC, sighoya wrote: A more natural conclusion would be to infer c to the most common supertype as other inferences would unnecessarily exclude future assignments to c. But the most common supertype doesn't seem to exist, and I'm unsure if this type can

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread sighoya via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 16:17:02 UTC, Marcone wrote: import std; void a(int b){ } void main() { Variant c = 10; a(c); // Error } Need more sugar. Two problems: 1.) Variant is library defined, compared to the language level there isn't a default strategy to choose int32 here, i

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/21 8:17 AM, Marcone wrote: > import std; > > void a(int b){ > } > > void main() > { >Variant c = 10; >a(c); // Error > } > > Need more sugar. That can't work in a strongly statically typed language. The call a(c) is decided at compile time but Variant is not an int at compile ti

Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Marcone via Digitalmars-d-learn
import std; void a(int b){ } void main() { Variant c = 10; a(c); // Error } Need more sugar.