|
|
|
|
|
by crabbone
1204 days ago
|
|
> If you can't create a value of type PrimeNumber that doesn't contain a prime number Because you wrote a validation function, the exact thing OP told you not to do. Hooray?! The goal of OP was to create a type that incorporates constraints on data, just like in their example about the non-empty list they created a type that in the type itself contains the constraints s.t. it's impossible to implement this type in a way that it will have an empty list. You did the opposite. You created a type w/o any constraints whatsoever, and then added a validation function to it to make sure you only create values validated by that function. So... you kind of proved my point: it's nigh impossible to create a program intelligible to human beings that has a "prime number" type, and that's why we use validation -- it's easy to write, easy to understand. Your type isn't even a natural number, let alone a prime number. |
|
Parsing is an additional job on top of validation - providing type-level evidence that the data is good. That's what makes it valuable. It's not some theoretical difference in power. It's better software engineering.