distributors-0.6.0.0: Unifying Parsers, Printers & Grammars
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Control.Lens.Grammar.Internal.NestedPrismTH

Description

Code is duplicated from PrismTH, with small tweaks to support nested pairs.

Synopsis

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) ()