Automatic typing

Walter Bright newshound2 at digitalmars.com
Fri Jun 28 15:29:21 PDT 2013


On 6/27/2013 5:34 PM, JS wrote:
> Would it be possible for a language(specifically d) to have the ability to
> automatically type a variable by looking at its use cases without adding too
> much complexity? It seems to me that most compilers already can infer type
> mismatchs which would allow them to handle stuff like:
>
> main()
> {
>     auto x;
>     auto y;
>     x = 3;   // x is an int, same as auto x = 3;
>     y = f(); // y is the same type as what f() returns
>     x = 3.9; // x is really a float, no mismatch with previous type(int)
> }
>
> in this case x and y's type is inferred from future use. The compiler
> essentially just lazily infers the variable type. Obviously ambiguity will
> generate an error.
>

I don't see a compelling use case for this proposal, or even any use case. 
There'd have to be some serious advantage to it to justify its complexity.


More information about the Digitalmars-d mailing list