On 9/20/10 11:09 AM, Graydon Hoare wrote:
Is it possible to infer the type from the expression, e.g. in 2 + x
the 2 matches the declared type of x?

Plausible. Go takes a similar angle on this; their numeric literals are
"untyped" and acquire a type via inference from the context. I'm not
sure I'm really keen on that -- every additional complication to
inference is a bit of a penalty to implementers, tools and future
readers -- but it could work.

Any feelings from others? Particularly .. those who have worked on the
type inference module :)

I'm also somewhat opposed to the proposal. To me, the strict typing of numeric literals is a great feature of Rust: it lets the programmer look at the code and immediately tell what's going to happen in the generated instructions and memory layout. C's integer promotion rules are confusing; by looking at C code I can never really tell precisely which instruction is going to be emitted.

Adding Go-style untyped numeric literals would also be difficult to reconcile with our type inference and polymorphic binary operators: what's the type of x in "auto x = 2 + 3;"?

Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to