| Copyright | (C) 2026 - Eitan Chatav |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Eitan Chatav <eitan.chatav@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Lens.Grammar.Internal.NestedPrismTH
Contents
Description
Code is duplicated from PrismTH,
with small tweaks to support nested pairs.
Synopsis
- makeNestedPrisms :: Name -> DecsQ
Nested prisms
makeNestedPrisms :: Name -> DecsQ Source #
Similar to makePrisms,
makeNestedPrisms generates a Prism
for each constructor of a data type.
Isos are generated when possible.
Reviews are generated for constructors
with existentially quantified constructors and GADTs.
The difference in makeNestedPrisms
is that constructors with n > 2 arguments
will use right-nested pairs, rather than a flat n-tuple.
This makes them suitable for pattern bonding,
by use of the applicator >?
to Monoidal idiom notation
with >*<,
or to Monadic qualified do-notation.
e.g.
data FooBar a = Foo a | Bar Int | Baz Int Char | Buzz Double String Bool | Boop makeNestedPrisms ''FooBar
will create
_Foo :: Prism (FooBar a) (FooBar b) a b _Bar :: Prism' (FooBar a) Int _Baz :: Prism' (FooBar a) (Int, Char) _Buzz :: Prism' (FooBar a) (Double, (String, Bool)) _Boop :: Prism' (FooBar a) ()