Automatic typing

Walter Bright newshound2 at digitalmars.com
Sat Jun 29 15:30:12 PDT 2013


On 6/29/2013 2:53 PM, Ary Borenszweig wrote:
> On 6/29/13 6:01 PM, Walter Bright wrote:
>> On 6/29/2013 12:18 PM, Ary Borenszweig wrote:
>>> What you are asking is essentially what Crystal does for all variables
>>> (and types):
>>>
>>> https://github.com/manastech/crystal/wiki/Introduction#type-inference
>>>
>>> Your example would be written like this:
>>>
>>> x = 3
>>> y = f()
>>> x = 3.9
>>>
>>> But since Crystal transforms your code to SSA
>>> (http://en.wikipedia.org/wiki/Static_single_assignment_form) you
>>> actually have
>>> *two* "x" variables in your code. The first one is of type Int32, the
>>> second of
>>> type Float64.
>>
>> Sorry, but that seems like a solution in search of a problem.
>>
>> And besides, yuk. Imagine the bugs caused by "hey, it doesn't implicitly
>> convert, so instead of letting the user know he goofed, let's just
>> silently create a new variable!"
>
> Sorry, but I can't imagine those bugs. Can you show me an example?

Sure:

x = 3
px = &x
y = f()
x = 3.9
// uh-oh, *px points to a different x, and wasn't updated!
printf("%d\n", x);  // uh-oh, I thought x was an int!


More information about the Digitalmars-d mailing list