lens-adt-1.0.0.0
Safe HaskellNone
LanguageHaskell2010

Control.Lens.TH.ADT

Description

This module allows generating lenses for non-record ADTs.

To allow overloading (e.g. using the same lens name for multiple ADTs), it first generates a typeclass and then an instance for it. If other lenses generated in the same scope have the same name, only an instance is generated.

data A = A Int
data B = B Int

makeADTLenses 'A ["value"]

-- ===> Generates the following
class HasValue a b where
 value = 'Lens'' a b

instance HasValue A Int where
 value = position 1

makeADTLenses 'B ["value"]

-- ===> Generates the following

instance HasValue B Int where
 value = position 1
Synopsis

Documentation

makeADTLenses :: Name -> [String] -> DecsQ Source #

Generates lenses for all the fields of the given type. Uses makeADTLens for each field.

makeADTLens :: Name -> String -> Int -> DecsQ Source #

Generates a lens with the given name for the field at the given index for the given type

makeADTLens '(,) "left" 0

-- ===> Generates the following
instance HasLeft (a,b) a where
 left = position @1

lensClassName :: Name -> Name Source #

Get the name of the lens typeclass to define, using the lens' name