3 ms·
If the operation can fail, that should really be represented in the type, right?
by truculent 3y ago
If the operation can fail, that should really be represented in the type, right?
- zokier 3y agoOne of my random thoughts is that floats could be represented as enums in type system, e.g. in rust-like syntax: #[repr(f32)] enum Float32 { PositiveInfinity, NegativeInfinity, Nan(NanPayload32), Finite(FiniteFloat32), } You could also then define NonNanFloat32 etc which could be used for certain operations. Of course on machine level its all the same
- truculent 3y agoYeah, I think something like this would make sense. I get why people might not like it, but this is what we’re dealing with whether we like it or not.
- brabel 3y agoNo necessarily. Rust doesn't do that for array indexing (though bound checking is enabled at runtime and will panic if out of bounds), division by zero, numeric overflow and probably many cases where it was deemed to be just too cumbersome.
- truculent 3y agoTrue, but iirc Rust also supplies a `get` method for when you want to get elements safely.