4 ms·
> Furthermore, the units are used only at compile time. At run time, a Length<Inch, f32> value is stored in memory as just a single f32 floating point value, wi
by portmanteaufu 12y ago
> Furthermore, the units are used only at compile time. At run time, a Length<Inch, f32> value is stored in memory as just a single f32 floating point value, with no additional data. The units are “phantom types” that are never instantiated and have no run-time behavior.
I love that you get all of this safety with zero runtime cost.
- dllthomas 12y agoThis is the difference between types and tags (sometimes they're conflated).
- illumen 12y agoThis code is buggy because they are using floats internally. A 32bit float can not represent the exact measurements specified. This is a perfect example of why just statically type checking your code does not make it correct.