Safe Haskell | None |
---|---|
Language | Haskell2010 |
Documentation
Predicates may be generated inline from a constructor name or quoted pattern, or in bulk from a type declaration.
You must enable the TemplateHaskell
extension to use the functions in this module.
From constructors
From patterns
From type declaration
Given a type T
, for each constructor K
, we can declare predicates
isK, isNotK : T → Bool
.
Type T
can be a newtype
, data
, or GADT
declaration.
Constructors with non-alphanumeric names (e.g. :+:
) are ignored
silently. As a workaround, we suggest giving the constructors
alphanumeric names, and creating pattern synonyms with the desired
symbolic names.
data E a where Plus :: E Int -> E Int -> E Int And :: E Bool -> E Bool -> E Bool Lit :: a -> E a (:*:) :: (Num a) => E a -> E a -> E a Showable :: (Show a) => a -> E String pattern a :+: b = Plus a b
makePredicates :: Name -> Q [Dec] Source #
Generate predicates of the form isK
>>>
$(makePredicates ''E)
>>>
isPlus (Plus (Lit 1) (Lit 2))
True