Automatic typing

John Colvin john.loughran.colvin at gmail.com
Fri Jun 28 15:30:50 PDT 2013


On Friday, 28 June 2013 at 22:29:21 UTC, Walter Bright wrote:
> 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.

My thoughts too. It's a lot of work for a very minor (and perhaps 
rather unwise) convenience.


More information about the Digitalmars-d mailing list