matchable-th: Generates Matchable instances using TemplateHaskell

[ bsd3, functors, library ] [ Propose Tags ] [ Report a vulnerability ]

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

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

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), bifunctors (>=5.1), matchable (>=0.1.2), template-haskell (>=2.4 && <2.23), th-abstraction (>=0.4.0.0) [details]
Tested with ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.6, ghc ==9.8.2, ghc ==9.10.1
License BSD-3-Clause
Author Koji Miyazato
Maintainer viercc@gmail.com
Revised Revision 1 made by viercc at 2024-09-12T03:02:26Z
Category Functors
Source repo head: git clone https://github.com/viercc/matchable -b master
Uploaded by viercc at 2023-04-07T04:01:00Z
Distributions NixOS:0.2
Downloads 1231 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-04-07 [all 1 reports]

Readme for matchable-th-0.2

[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.

Examples

{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}

import Data.Functor.Classes (Eq1(..))
import Data.Matchable
import Data.Matchable.TH ( deriveInstances )

newtype G a = G [(a, Int, a)]
  deriving (Show, Eq, Functor)

deriveInstances [d|
  deriving instance Eq1 G
  deriving instance Matchable G
  |]

{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}

import Data.Functor.Classes ( Eq1, Eq2 )
import Data.Bifunctor ( Bifunctor(..) )
import Data.Bimatchable ( Bimatchable )
import Data.Matchable ( Matchable )
import Data.Matchable.TH ( deriveInstances )

-- Test case for using [], tuple, and another Bimatchable instance
data BiG a b = BiG0 | BiG1 [a] [b] | BiG2 (Int, BiF a b)
  deriving (Show, Eq)

deriveInstances [d|
  deriving instance Bifunctor BiG
  deriving instance Eq a => Eq1 (BiG a)
  deriving instance Eq a => Matchable (BiG a)
  deriving instance Eq2 BiG
  deriving instance Bimatchable BiG
  |]