|
|
|
|
|
by Jtsummers
1611 days ago
|
|
The first part of that page demonstrates what amounts to pre/post conditions, but placed in the constructor. The range is checked dynamically, not statically. The second part is using Peano numbers to enforce the constraint. I guess you could try and force that into some mainstream languages, probably C++. With its template programming you could get something going in this vein, though I'm not sure how well it would work if the number were calculated at runtime rather than compile time. You'd still end up with a dynamic check somewhere. |
|
If you need to statically check the construction of values in Haskell, there are things like refinement types[0].
[0]: http://nikita-volkov.github.io/refined/