bidirectional-instances-0.1.0.0: Make instance constraints bidirectional
CopyrightLev Dvorkin (c) 2022
LicenseMIT
Maintainerlev_135@mail.ru
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Control.Bidirectional.TH

Description

 
Synopsis

Documentation

decBidirectionalInstances :: Q [Dec] -> Q [Dec] Source #

Declare instance and make it bidirectional at the same time. Provides instances for Bidirectional and BidirectionalRec.

It's suitable for declaring your own instances. To make existing instances (for example, from libs) bidirectional, use makeBidirectionalInstances.

You can use it for declaring multiple instances:

data A a = A a
data B a b = B a b
data C a b = CA a | CB b

decBidirectionalInstances [d| 
    instance Show a => Show (A a) where
      show (A a) = "A " ++ show a
    instance (Show a, Show b) => Show (B a b) where
      show (B a b) = "B " ++ show a ++ " " show b
    instance (Show a, Show b) => Show (C a b) where
      show (CA a) = "CA " ++ show a
      show (CB b) = "CB " ++ show b
  |] 

makeBidirectionalInstances :: Q [Dec] -> Q [Dec] Source #

Make existing instance bidirectional. Provides instances for Bidirectional and BidirectionalRec.

It's suitable for making bidirectional existing instances, that you can't change (for example, from libs). If you want to declare your one instance and make it bidirectional, use decBidirectionalInstances.

You can use it for declaring multiple instances:

makeBidirectionalInstances [d| 
    instance Show a => Show [a]
    instance (Show a, Show b) => Show (a, b)
    instance (Show a, Show b) => Show (Either a b)
  |] 

Note that you need not provide the body of instance, only its head.