2 ms·
> For example, what is the type of Inch * Inch? An area, inch^2. > What is the type of Inch / Inch? A unitless ratio? I don't understand why this is not pra
by esafak 3y ago
> For example, what is the type of Inch * Inch?
An area, inch^2.
> What is the type of Inch / Inch?
A unitless ratio?
I don't understand why this is not practical in safety-critical software. nyssos demonstrated what I believe is the right way to do it.
- bjourne 3y agoThese semantics make the type incompatible with the Num class and attempting to plug your type into, say, a run of the mill ode solver likely won't do what you want. So you have two options. 1) Rewrite all code to become "quantity aware". Multiplying two Matrix[Inch] results in a Matrix[Inch2] and so on. 2) Litter your code with floatToInch and inchToFloat conversions. I think you can see why both options suck? If you really can't, then perhaps try finding some safety-critical software that relies on "physical quantity types" in some form or another?
- deleted 3y ago[deleted]
- freilanzer 3y ago> I think you can see why both options suck? Do they suck more than losing spacecraft?
- bjourne 3y agoAbsolutely. Littering a code base with centimeter-to-inch conversions or rewriting every numeric computation to become unit aware would for sure have caused more bugs than it would have prevented.