| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Matchable.TH
Synopsis
- deriveMatchable :: Name -> Q [Dec]
- makeZipMatchWith :: Name -> ExpQ
- deriveBimatchable :: Name -> Q [Dec]
- makeBizipMatchWith :: Name -> ExpQ
Documentation
deriveMatchable :: Name -> Q [Dec] Source #
Build an instance of Matchable for a data type.
e.g.
data Exp a = Plus a a | Times a a
deriveMatchable ''Exp
will create
instance Matchable Exp where zipMatchWith f (Plus l1 l2) (Plus r1 r2) = pure Plus * f l1 r1 * f l2 r2 zipMatchWith f (Times l1 l2) (Times r1 r2) = pure Times * f l1 r1 * f l2 r2 zipMatchWith _ _ _ = Nothing
makeZipMatchWith :: Name -> ExpQ Source #
deriveBimatchable :: Name -> Q [Dec] Source #
Build an instance of Bimatchable for a data type.
e.g.
data Sum a b = InL a | InR b
deriveMatchable ''Sum
will create
instance Matchable Sum where bizipMatchWith f _ (InL l1) (InL r1) = pure InL $ f l1 r1 bizipMatchWith _ g (InR l1) (InR r1) = pure InR $ g l1 r1
makeBizipMatchWith :: Name -> ExpQ Source #