Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- deriveInstances :: Q [Dec] -> Q [Dec]
- deriveMatchable :: Name -> Q [Dec]
- makeZipMatchWith :: Name -> ExpQ
- deriveBimatchable :: Name -> Q [Dec]
- makeBizipMatchWith :: Name -> ExpQ
- makeLiftEq :: Name -> Q Exp
- makeLiftEq2 :: Name -> Q Exp
Documentation
deriveInstances :: Q [Dec] -> Q [Dec] Source #
This function transforms multiple instance declarations written in StandaloneDeriving
format to instances derived by TemplateHaskell.
Example
{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE StandaloneDeriving #-} [-# LANGUAGE TemplateHaskell #-} data Foo a b = Foo a b (Either a b) deriving (Show, Eq, Functor)
To use deriveInstances
for Foo
, write as below:
deriveInstances [d| deriving instance Eq a => Eq1 (Foo a) deriving instance Eq a => Matchable (Foo a) deriving instance Eq2 Foo deriving instance Bifunctor Foo deriving instance Bimatchable Foo |]
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 #