On 6/29/13 7:30 PM, Walter Bright wrote:
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!

If the last statements were:

x = 4
printf("%d\n", *px);

I can see where the problem is (you would expect that to print 4, right?). That can be easily fixed by not transforming the last x to SSA if its address is taken.

That's a really good example you gave :-)

Reply via email to