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

> I use schema libraries and asserts to both document the code and make sure you can't feed it wrong data.

Dependent types to the rescue!



Dependent types to the rescue!

Dependent types are nice, but much what the grandparent wants can be achieved fine with normal types. E.g. in Haskell, define the Longitude type and some helper functions

  newtype Longitude = Longitude Double

  fromDouble :: Double -> Maybe Longitude
  ...
And don't export the Longitude constructor to maintain invariants. Obviously, the same can be done in OO languages that allow you to hide members, C (via opaque pointers), etc.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: