Stability | provisional |
---|---|
Maintainer | Hugo Pacheco <hpacheco@nii.ac.jp> |
Safe Haskell | None |
Template Haskell procedures to generate default putlenses for record types and default putlens constructors and destructores for Generic
instances.
- makePutlensFields :: Name -> Q [Dec]
- makePutlensConstructors :: Name -> Q [Dec]
Documentation
makePutlensFields :: Name -> Q [Dec]Source
Generates field putlenses for record types
For a record
data T a = T { t1 :: String, t2 :: a }
$( makePutlensFields ''T )
it generates two putlenses
t1Put :: Putlens st e (T a) String
t2Put :: Putlens st e (T a) a
makePutlensConstructors :: Name -> Q [Dec]Source
Generates constructor and destructor putlenses for data types that are Generic
instances
For an algebraic data type
data List a = Nil | Cons a [a] deriving Generic
$( makePutlensConstructors ''List )
it generates two constructors
nilPut :: Putlens st e (List a) ()
nilPut = innPut .< injlPut
consPut :: Putlens st e (List a) (a,List a)
consPut = innPut .< injrPut
and two destructors
unnilPut :: Putlens st e () (List a)
unnilPut = uninjlPut .< outPut
unconsPut :: Putlens st e (a,List a) (List a)
unconsPut = uninjrPut .< outPut