- empty = failure (SomeFailure FailureEmpty)
-
-data instance Failure CombAlternable
- = FailureEmpty
- deriving (Eq, Ord, Show, TH.Lift, Generic, NFData)
-
--- ** Data family 'Failure'
--- | 'Failure's of the 'Grammar'.
--- This is an extensible data-type.
-data family Failure
- (comb :: ReprComb -> Constraint)
- :: Type
-
-{-
--- | Convenient utility to pattern-match a 'SomeFailure'.
-pattern Failure :: Typeable comb => Failure comb -> SomeFailure
-pattern Failure x <- (unSomeFailure -> Just x)
--}
-
--- ** Type 'SomeFailure'
-data SomeFailure =
- forall comb.
- ( Eq (Failure comb)
- , Ord (Failure comb)
- , Show (Failure comb)
- , TH.Lift (Failure comb)
- , NFData (Failure comb)
- , Typeable comb
- ) => SomeFailure (Failure comb {-repr a-})
-instance Eq SomeFailure where
- SomeFailure (x::Failure x) == SomeFailure (y::Failure y) =
- case typeRep @x `eqTypeRep` typeRep @y of
- Just HRefl -> x == y
- Nothing -> False
-instance Ord SomeFailure where
- SomeFailure (x::Failure x) `compare` SomeFailure (y::Failure y) =
- -- WARNING: this ordering is convenient to make a 'Set' of 'SomeFailure's
- -- but it is based upon a hash which changes with packages' ABI
- -- and also if the install is "inplace" or not.
- -- Therefore this 'Ord' is not stable enough to put 'SomeFailure'
- -- in golden tests.
- let xT = typeRep @x in
- let yT = typeRep @y in
- case SomeTypeRep xT `compare` SomeTypeRep yT of
- EQ | Just HRefl <- xT `eqTypeRep` yT -> compare x y
- o -> o
-instance Show SomeFailure where
- showsPrec p (SomeFailure x) = showsPrec p x
-instance TH.Lift SomeFailure where
- liftTyped (SomeFailure x) = [|| SomeFailure $$(TH.liftTyped x) ||]
-instance NFData SomeFailure where
- rnf (SomeFailure x) = rnf x
-
-{-
-instance Derivable (SomeFailure repr) where
- derive (SomeFailure x) = derive x
--}
-
--- | @(unSomeFailure c :: 'Maybe' ('Failure' comb repr a))@
--- extract the data-constructor from the given 'SomeFailure'
--- iif. it belongs to the @('Failure' comb repr a)@ data-instance.
-unSomeFailure :: forall comb. Typeable comb => SomeFailure -> Maybe (Failure comb)
-unSomeFailure (SomeFailure (c::Failure c)) =
- case typeRep @comb `eqTypeRep` typeRep @c of
- Just HRefl -> Just c
- Nothing -> Nothing