Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


You’ll be glad to learn that there is absolutely no overhead in execution time or memory consumed (and a minuscule one in compilation time).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: