Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider making genValidStructurally the default #76

Closed
NorfairKing opened this issue Feb 28, 2020 · 1 comment
Closed

Consider making genValidStructurally the default #76

NorfairKing opened this issue Feb 28, 2020 · 1 comment

Comments

@NorfairKing
Copy link
Owner

Currently the default implementation for GenValid is

genValid = genUnchecked `suchThat` isValid

Pros:

  1. It's always correct, even if isValid explicitly doesn't require validity of a subpart.
    For example in
newtype InvalidRational = InvalidRational Rational

instance Validity InvalidRational where
  validate = trivialValidation

Admittedly, this is a pretty rare occurrence.

  1. It does not require a Generic instance (as long as GenUnchecked didn't need one either).

The alternative is to have the default implementation be:

genValid = genValidStructurally

Pros: It's closer to what you want, usually. Eventhough an override is still necessary when you want genValidStructurallyWithoutExtraChecking.
Cons: It's not always correct, see the first pro of the current approach.

@NorfairKing
Copy link
Owner Author

It turns out you don't actually want this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant