In json, there’s considerable confusion possible, as you don’t know how much precision is “actually represented”. For example, is “1.3” meant as a float, as a double, as a big decimal? In most languages, (double)1.3f prints as 1.299…, and is different from 1.3
Then again... I have a little more trouble discarding floats as keys, including floats as set members.
And anyway, you can't stop floats from being weird. 0 vs -0. NaN. +/-Infinity.
let a: Int = 1 // let a = Int(1)
let b: Float = 1.0 // let b = Float(1.0)
Even so, I think this is solvable by:- De-composing the numeric value for comparison only
- De-composing and re-composing the numeric value for assignment
If you can’t do either, i.e. because one underlying value is inherently incompatible with the other in some way, then you have a static type error regardless of how your semantically distinct types interact.
A float actually sounds like the perfect way to index a list: anything in the range from from 0 to 1 (excluding either) would map to the first element. It works just like the wheel of fortune. Well almost, with the wheel exactly 0 or 1 would be invalid. So you might want to index using 0.5, 1.5, etc instead, and the implementation can round up or down the way it wants. We've solved a language incompatibility issue, lol </rant>