Skip to content

Optional Show instances #1

@cdsmith

Description

@cdsmith

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions