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

The pursuit of "better" languages might be incomplete, but it has long been known that this specific problem can be solved by the newtype pattern. It might have originated in Haskell but it's equally applicable in more traditional languages like C++. All you need is to define a named struct containing an integer called PhysicalSize and another one called AllocatedSize. In C++ add operator overloading to it so you can do arithmetic. In Haskell add instances such as Integral and Num.


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

Search: