matchable-th: Generates Matchable instances using TemplateHaskell

[ bsd3, functors, library ] [ Propose Tags ]

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


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.2.0, 0.1.2.1, 0.2
Change log CHANGELOG.md
Dependencies base (>=4.10 && <5), matchable (>=0.1.2), template-haskell (>=2.4 && <2.17), th-abstraction (>=0.4.0.0) [details]
License BSD-3-Clause
Author Koji Miyazato
Maintainer viercc@gmail.com
Category Functors
Source repo head: git clone https://github.com/viercc/matchable -b master
Uploaded by viercc at 2020-10-13T10:37:01Z
Distributions NixOS:0.2
Downloads 1102 total (16 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-10-13 [all 1 reports]

Readme for matchable-th-0.1.1.1

[back to package description]

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

-- 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)