Control.Lens.Internal.PrismTH

lens-4.14: Lenses, Folds and Traversals

Copyright | (C) 2014-2016 Edward Kmett and Eric Mertens
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Trustworthy
Language | Haskell98

Control.Lens.Internal.PrismTH

Description

Synopsis

- makePrisms :: Name -> DecsQ
- makeClassyPrisms :: Name -> DecsQ
- makeDecPrisms :: Bool -> Dec -> DecsQ

# Documentation

makePrisms #

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)

makeClassyPrisms #

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.

makeDecPrisms #

Arguments

:: Bool | generate top-level definitions
-> Dec |
-> DecsQ |

Generate prisms for the given `Dec`