3 ms·
The Rust error messages are much better though. This program: fn main() { println!("{}", (6 / 2) + 1.0); } fails to compile with the following
by nicoburns 7y ago
The Rust error messages are much better though. This program:
fn main() {
println!("{}", (6 / 2) + 1.0);
}
fails to compile with the following error message:
error[E0277]: cannot add a float to an integer
--> src/main.rs:3:28
|
3 | println!("{}", (6 / 2) + 1.0);
| ^ no implementation for `{integer} + {float}`
|
= help: the trait `std::ops::Add<{float}>` is not implemented for `{integer}`
- twic 7y agoThe crucial difference to Haskell is that this program: fn main() { println!("{}", 3 + 1.0); } Also fails with substantially the same error message. Rust is consistent that you can't add integers to floats. Haskell's looseness around numeric literals means that it isn't. Mind you, Rust does have that kind of looseness within the integers, so this: fn three() -> u8 { 3 } fn one() -> u16 { 1 } fn main() { println!("{}", 3 + 1); println!("{}", 3 + one()); println!("{}", three() + 1); println!("{}", three() + one()); } Fails to compile only on the last println.