3 ms·
I had a similar thought- Rust has "tuple structs" which are effectively structs without property names. You could make singletons: struct Relative(i32); st
by _bxg1 7y ago
I had a similar thought- Rust has "tuple structs" which are effectively structs without property names. You could make singletons:
struct Relative(i32);
struct Absolute(i32);
let foo = Relative(12);
let bar = Absolute(12);
fn useAbsolute(coord: Absolute);
useAbsolute(foo); // Err!
and effectively get this idea enforced at the type level. Of course support for this pattern would vary by language, and there would probably be some small overhead, but it could be worth it.
- navaati 7y agoYou’ll be glad to learn that there is absolutely no overhead in execution time or memory consumed (and a minuscule one in compilation time).