@hackage matchable-th0.1.0.0
Generates Matchable instances using TemplateHaskell
Installation
Dependencies (4)
- base >=4.9 && <5
- matchable >=0.1.2
- template-haskell >=2.4 && <2.15
- th-abstraction <0.3 Show all…
Dependents (0)
matchable-th
This package provides TemplateHaskell functions to
generate instances of Matchable and Bimatchable type classes,
which are from matchable package.
Example
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TemplateHaskell #-}
import Data.Functor.Classes (Eq1(..))
import Data.Matchable
import Data.Matchable.TH
newtype G a = G [(a, Int, a)]
deriving (Show, Eq, Functor)
$(deriveMatchable ''G)
-- @deriveMatchable@ generates a @Matchable@ instance only,
-- so you also have to declare @Functor G@ and @Eq1 G@.
-- There is a handy @DeriveFunctor@ extension.
-- Also, you can use @liftEqDefault@ to easily implement @liftEq@.
instance Eq1 G where
liftEq = liftEqDefault
{-# LANGUAGE TemplateHaskell #-}
import Data.Functor.Classes (Eq2(..))
import Data.Bimatchable
import Data.Matchable.TH
data BiG a b = BiG0 | BiG1 [a] [b] | BiG2 (Int, BiF a b)
instance Eq2 BiG where
liftEq2 = liftEq2Default
instance Bifunctor BiG where
bimap = bimapRecovered
$(deriveBimatchable ''BiG)