4 ms·
I agree broadly with this however in many cases that I have been dealing with I don't think that there can be a type system that would be rich enough to encode
by qtplatypus 7y ago
I agree broadly with this however in many cases that I have been dealing with I don't think that there can be a type system that would be rich enough to encode the validation laws.
For example how would you encode "This purchase request must be made before the closing date for the purchase"?
- undreren 7y agoThis sounds like the Nirvana fallacy. Just because parsing over validation is not perfect, it can still lead to significantly more maintainable code and safer and stabler system. Pure validation has a lot of problems, namely that you have to validate the data on all levels for the invariants required at that level.
- lkitching 7y agoThis isn't about encoding the validation rules in the type system, only the requirement that validation with respect to some properties has been done. So in your example you would just define a function createPurchaseRequest :: UserRequest -> Purchase -> Maybe PurchaseRequest now everywhere in the code taking a PurchaseRequest can assume it is valid.