Earlier quoted context omitted.
Range types are probably the main thing I miss from the Rust type system. But even without range constraints, wrapper types (called newtypes in Haskell and Rust) are great. Let's say you have a function that accepts a temperature. A temperature is a float, but you want to prevent the user from mixing up celsius and fahrenheit. This is what newtype looks like in Rust: struct Celsius(pub f64); struct Fahrenheit(pub f64…
Huh. That's clever. This approach should also work in other languages, say, C/C++/C#. I don't remember if C uses structural identity for struct types, but it might work.
Not that you can use the language-provided == on floats anyway, due to precision issues you should always check if the difference is below a specified limit...