|
|
|
|
|
by pcwalton
4155 days ago
|
|
> Except where they can't, and those locations aren't terribly consistent. Why aren't they consistent? The Rust type inference is generally very good, and the places where you have to annotate are places where any typechecker would force you to annotate, because the types are simply underconstrained (e.g. the return type of Vec::collect or mem::transmute). > The Rust designers have publicly announced their preference for explicitness over inference, and the language reflects that. As the original author of the typechecker, I can state that the idea that we intentionally made the type inference less powerful than it could have been is totally false. It's always been as powerful as we could make it, except for interface boundaries (where type annotation is needed because of separate compilation anyway). |
|
So, I went back to do a bit of research, and it's gotten better since this first bothered me, my apologies. My beef was with the `let x = vet::Vector::New::<i32>()` vs `let x: Vec<i32> = vec::Vec::New()`. Perhaps not the best way to word it, so consider this objection retracted. :)
> the idea that we intentionally made the type inference less powerful than it could have been is totally false
Except for function definitions, where the types could be inferred from the function bodies, but are not:
https://www.reddit.com/r/rust/comments/2bcof3/rust_type_infe...
Plus (and this is more related to the complete lack of implicit type conversions), there are types everywhere in the program. I frequently can't write a number without having to append a type, even when the type has been explicitly defined previously.
Here's one of my favorites from a recent attempt to write a ray tracer: