3 ms·
> 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!
by adamnemecek 13y ago
> 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!
- danieldk 13y agoDependent 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.