lens-4.4.0.1: Lenses, Folds and Traversals

Portabilitynon-portable
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellNone

Control.Lens.Internal.PrismTH

Description

 

Synopsis

Documentation

makePrismsSource

Arguments

:: Name

Type constructor name

-> DecsQ 

Generate a Prism for each constructor of a data type. Isos generated when possible. Reviews are created for constructors with existentially quantified constructors and GADTs.

e.g.

 data FooBarBaz a
   = Foo Int
   | Bar a
   | Baz Int Char
 makePrisms ''FooBarBaz

will create

 _Foo :: Prism' (FooBarBaz a) Int
 _Bar :: Prism (FooBarBaz a) (FooBarBaz b) a b
 _Baz :: Prism' (FooBarBaz a) (Int, Char)

makeClassyPrismsSource

Arguments

:: Name

Type constructor name

-> DecsQ 

Generate a Prism for each constructor of a data type and combine them into a single class. No Isos are created. Reviews are created for constructors with existentially quantified constructors and GADTs.

e.g.

 data FooBarBaz a
   = Foo Int
   | Bar a
   | Baz Int Char
 makeClassyPrisms ''FooBarBaz

will create

class AsFooBarBaz s a | s -> a where _FooBarBaz :: Prism' s (FooBarBaz a) _Foo :: Prism' s Int _Bar :: Prism' s a _Baz :: Prism' s (Int,Char) _Foo = _FooBarBaz . _Foo _Bar = _FooBarBaz . _Bar _Baz = _FooBarBaz . _Baz instance AsFooBarBaz (FooBarBaz a) a | Generate an As class of prisms. Names are selected by prefixing the constructor name with an underscore. Constructors with multiple fields will construct Prisms to tuples of those fields.

makeDecPrismsSource

Arguments

:: Bool

generate top-level definitions

-> Dec 
-> DecsQ 

Generate prisms for the given Dec