Re:Parse, Don't Validate (2019)
by esrauch on Tuesday March 07, 2023 @05:48PM
(#35062414)
What if you want it to only be less that 100 though? Not everything is so easily expressable the way you're saying.
[ Parent
| on HN ]
You can go as far or (as short) as the application warrants. The more static evidence you want, the more cumbersome it's going to become. That seems sort of a natural progression, but the the point is that you get to choose the trade-off. It's often easier to prove a special case than a more general case.
(Certainly, Haskell is probably not the most concise language for this kind of thing. LiquidHaskell adds interesting proof capabilities wrt. arithmetic.)
Regardless, even just parsing at the boundary and using an opaque type
MySuperSpecialInt = Int @Even Min(2) Max(100)
(or whatever syntax you want) is still better than just using Int. At least you'll know that you'll always be handed a value that's in range (post-parsing).
Re:Parse, Don't Validate (2019)
by lexi-lambda on Wednesday March 08, 2023 @07:24AM
(#35068165)
Yes, certainly. Constructive data modeling is useful for many things, but it’s not a panacea. Other techniques are useful in cases where it’s not practical; I discuss some of the tradeoffs in this followup post: https://lexi-lambda.github.io/blog/2020/11/01/names-are-not-...