|
|
|
|
|
by Quekid5
1207 days ago
|
|
I don't disagree that dependent types would help (and be really cool for lots of other uses!), but let's consider what the usual validation rules that we really need are: non-empty, basic interval constraints (non-negative/positive), only contains a certain set of characters... simple stuff like that, usually. If we're going wild, an interesting case would be effectful validation and how that fits in. In practice, what happens with any non-basic validation is that the server says 3xx, try again. Anyway, validation/parsing is mostly pretty simple stuff where the "validate" bit is a simple function... and function composition works just fine. (Assuming you can name the result type of your parse/validate individually according to your domain.) |
|
You end up with four choices:
1. Have a single function that does all the constraint checking at once
2. Have a single linear order where each constraint check feeds into the next but only in that order
3. Acquiesce to a combinatorial explosion of functions that check every possible combination of those constraints
4. Give up keeping track of the constraints at a type level.