Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Template-Haskell helpers for EADTs
Documentation
Create a pattern synonym for an EADT constructor
E.g.
data ConsF a e = ConsF a e deriving (Functor) $(eadtPattern 'ConsF "Cons") ====> pattern Cons :: ConsF a :<: xs => a -> EADT xs -> EADT xs pattern Cons a l = VF (ConsF a l)
Create an infix pattern synonym for an EADT constructor
E.g.
data ConsF a e = ConsF a e deriving (Functor) $(eadtInfixPattern 'ConsF ":->") ====> pattern (:->) :: ConsF a :<: xs => a -> EADT xs -> EADT xs pattern a :-> l = VF (ConsF a l)
:: Name | Actual constructor (e.g., ConsF) |
-> String | Name of the pattern (e.g., Cons) |
-> Q Type | Type of the EADT (e.g., [t|forall a. List a|]) |
-> Q [Dec] |
Create a pattern synonym for an EADT constructor that is part of a specified EADT.
This can be useful to help the type inference because instead of using a generic "EADT xs" type, the pattern uses the provided type.
E.g.
data ConsF a e = ConsF a e deriving (Functor) data NilF e = NilF deriving (Functor) type List a = EADT '[ConsF a, NilF] $(eadtPatternT 'ConsF "ConsList" [t|forall a. List a|]) ====> pattern ConsList :: ( List a ~ EADT xs , ConsF a :<: xs ) => a -> List a -> List a pattern ConsList a l = VF (ConsF a l)
Note that you have to quantify free variables explicitly with forall