rerefined-0.5.1: Refinement types, again
Safe HaskellSafe-Inferred
LanguageGHC2021

Rerefined.Predicate.Via

Synopsis

Documentation

data Via pVia p Source #

Predicate p is implemented via predicate pVia.

This is useful when you need a unique data type for a predicate (e.g. for instances, clarity), but the predicate it tests already exists. In such cases, it would be nice to reuse the existing predicate, while printing both predicates in failures.

Via assists in doing this. Implement your Predicate instance as normal, then implement Refine with:

validate = validateVia @pVia

Now when this predicate fails, it will print the pVia failure with a wrapper stating the name of the original predicate.

Note that you may not use DerivingVia because it only works on the last parameter of a multi-parameter type class, and I don't want to switch the order of the Refine parameters. Even if I did, DerivingVia isn't much different to or easier than this.

Instances

Instances details
(Predicate p, Predicate pVia) => Predicate (Via pVia p :: Type) Source # 
Instance details

Defined in Rerefined.Predicate.Via

Associated Types

type PredicateName d (Via pVia p) :: Symbol Source #

(Refine pVia a, Predicate p, KnownPredicateName p) => Refine (Via pVia p :: Type) a Source # 
Instance details

Defined in Rerefined.Predicate.Via

Methods

validate :: Proxy# (Via pVia p) -> a -> Maybe RefineFailure Source #

type PredicateName d (Via pVia p :: Type) Source # 
Instance details

Defined in Rerefined.Predicate.Via

type PredicateName d (Via pVia p :: Type) = ShowParen (d > 9) ((("Via " ++ PredicateName 10 p) ++ " ") ++ PredicateName 10 pVia)

validateVia :: forall pVia p a. (Refine pVia a, Predicate p, KnownPredicateName p) => Proxy# p -> a -> Maybe RefineFailure Source #