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

move Typeable constraint on predicate kind to class #98

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

raehik
Copy link
Collaborator

@raehik raehik commented Apr 26, 2023

An earlier change #83 enabled using non-Type-kinded predicates. To support this, Predicate (p :: k) x instances were changed to explicitly include a Typeable k constraint. Every instance that wishes to support non-Type-kinded predicates (e.g. further predicate operators like And, Not) must add this constraint.

This PR moves the Typeable k constraint to the class definition. (Note that Typeable p was already present.) We remove lots of newly spurious Typeable constraints. We also fix an oversight in the instances for binary predicate operators, where the kind of predicates l and r were arbitrarily required to be the same kind k. Thanks to this change, we can remove the explicit kind quantifying and let GHC correctly infer l :: k1, r :: k2.

Due to GHC's rules on inferring type variable order, validate becomes awkward to use with TypeApplications. validate' provides original behaviour. Potential discussion there.

This might break certain custom predicate operator instances, but I'm not sure.

@raehik
Copy link
Collaborator Author

raehik commented Apr 26, 2023

A potential discussion on design:

validate' :: forall {k} ... is really the preferred external function signature. It would be nicer to switch the names of validate and validate'. However, it would break certain custom Predicate instances. In the first place validate is a fairly internal function, so I figured there wasn't a good enough reason to switch.

@raehik raehik changed the title move Typeable constraint on predicate kind to class move Typeable constraint on predicate kind to class Apr 26, 2023
@chessai
Copy link
Collaborator

chessai commented Apr 29, 2023

The type ordering is unfortunate. This looks good to me. Having both validate and validate' makes me sad, but like you said, it's mostly internal. The docs should definitely mention this issue though.

An earlier change enabled using non-`Type`-kinded predicates. To support
this, `Predicate (p :: k) x` instances were changed to explicitly
include a `Typeable k` constraint. Every instance that wishes to support
non-`Type`-kinded predicates must add this constraint.

This commit moves the constraint to the class definition. We remove
newly spurious `Typeable` constraints. Due to GHC's rules on inferring
type variable order, `validate` becomes awkward to use with
TypeApplications. `validate'` provides original behaviour.
@raehik raehik force-pushed the typeable-constraints-tweak branch from e5334b1 to b8fedb3 Compare May 3, 2023 15:50
@raehik
Copy link
Collaborator Author

raehik commented May 3, 2023

I clarified the validate' situation so there should be no confusion.

@raehik
Copy link
Collaborator Author

raehik commented Jun 16, 2023

@chessai any further thoughts on this PR? I'm using it in 2 projects without issue (though it is more of a library concern than user-facing)

@raehik
Copy link
Collaborator Author

raehik commented May 3, 2024

This is fairly ready to merge, but I'm loathe to push it forwards as I'd prefer to remove Typeable constraints from combinator predicates altogether. I've already done this in rerefined. See #101 for an overview of the changes required.

@chessai chessai merged commit 5f0c814 into nikita-volkov:master Nov 15, 2024
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

Successfully merging this pull request may close these issues.

2 participants