matchable-th: Generates Matchable instances using TemplateHaskell

[ bsd3, functors, library ] [ Propose Tags ]

This package defines a type class Matchable, providing zipMatch operation for zipping two values of any container-like functor type.

[Skip to Readme]
Versions [RSS] [faq],,,
Change log
Dependencies base (>=4.10 && <5), matchable (>=0.1.2), template-haskell (>=2.4 && <2.18), th-abstraction (>= [details]
License BSD-3-Clause
Author Koji Miyazato
Revised Revision 1 made by viercc at 2021-08-25T05:44:57Z
Category Functors
Source repo head: git clone -b master
Uploaded by viercc at 2021-08-25T05:37:54Z
Distributions NixOS:
Downloads 730 total (19 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-08-25 [all 1 reports]


[Index] [Quick Jump]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees


Readme for matchable-th-

[back to package description]


This package provides TemplateHaskell functions to generate instances of Matchable and Bimatchable type classes, which are from matchable package.


{-# 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

-- Most simple case
data BiF a b = BiF0 | BiF1 a b

instance Eq2 BiF where
  liftEq2 = liftEq2Default

instance Bifunctor BiF where
  bimap = bimapRecovered

$(deriveBimatchable ''BiF)

-- Test case for using [], tuple, and another Bimatchable instance
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)