matchable-th-0.1.1.1: Generates Matchable instances using TemplateHaskell

Safe HaskellNone
LanguageHaskell2010

Data.Matchable.TH

Synopsis

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

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