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

Optional Show instances #1

Open
cdsmith opened this issue Sep 19, 2021 · 0 comments
Open

Optional Show instances #1

cdsmith opened this issue Sep 19, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@cdsmith
Copy link
Owner

cdsmith commented Sep 19, 2021

Currently, many predicates make an arbitrary choice whether to require a Show instance or not. If a Show instance is required, then the Predicate can give better explanations, but can't be used as often. This isn't really a choice that's about the predicate, but rather about the type the predicate is used with.

By relying on https://hackage.haskell.org/package/if-instance, it would be possible to defer this decision to the call site, obtaining a Show instance that can be used if it's available, but otherwise falling back to something with worse messages but that still works! That's perfect. However, it's imperfect that if-instance depends on GHC 9.0, and requires that clients use a GHC plugin.

I think the right thing to do here is to create a different package that depends on explainable-predicates, reexports the same Predicate type, but defines the predicates to use optional Show instances via the plugin. Then users who can tolerate a GHC plugin and are using GHC 9.0 could depend in the new package instead.

Notes:

  • In the long-term, it would be very nice if explainable-predicates made it into GHC. However, that would still mean a delay of years before this package could depend on the functionality because of backward compatibility.
  • It would be nice if the implementation here could depend on the more generic implementation using if-instance. That would work, except for old GHC compatibility. Perhaps an upstream contribution could widen the range of GHC versions supported by if-instance. If that included everything as far back as 8.6, I think that would be good enough. But 9.0 definitely isn't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant