> A good type system (e.g Rust's, Haskell's..) can eliminate all type errors from your programs.
Do you consider silently trimming value during mandatory explicit type conversion a type error?
Do you consider silently trimming value during mandatory explicit type conversion a type error?
fn main() {
let x = 5i32;
let y: i64 = x.into();
println!("{}", y);
}
this doesn't work: fn main() {
let x = 5i32;
let y: i16 = x.into();
println!("{}", y);
}
you have to write: fn main() {
let x = 5i32;
let y = x as i16;
println!("{}", y);
}
where `as` has the potential of being lossy!The casting function could specify the valid input values, and force the programmer to handle the rest of the cases when the input type is wider.
This is a contradiction, something cannot be both silent and explicit.