HORIZON HASKELLDocslts/ghc-10.0.xc62e4de2026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · c62e4de · 2026-10-19

Modulelens-family-th-0.5.3.2Haskell2010

Lens.Family.TH

Derive lenses for Lens.Family.

Example usage:

{-# LANGUAGE TemplateHaskell #-}

import Lens.Family
import Lens.Family.TH

data Foo a = Foo { _bar :: Int, _baz :: a }
           deriving (Show, Read, Eq, Ord)
$(makeLenses ''Foo)
  • 7 values
valuemakeLenses :: Name -> Q [Dec]
#

Derive lenses for the record selectors in a single-constructor data declaration, or for the record selector in a newtype declaration. Lenses will only be generated for record fields which are prefixed with an underscore.

Example usage:

$(makeLenses ''Foo)
valuemakeLensesBy :: (String -> Maybe String) -> Name -> Q [Dec]
#

Derive lenses with the provided name transformation and filtering function. Produce Just lensName to generate a lens of the resultant name, or Nothing to not generate a lens for the input record name.

Example usage:

$(makeLensesBy (\n -> Just (n ++ "L")) ''Foo)
valuemakeLensesFor :: [(String, String)] -> Name -> Q [Dec]
#

Derive lenses, specifying explicit pairings of (fieldName, lensName).

Example usage:

$(makeLensesFor [("_foo", "fooLens"), ("bar", "lbar")] ''Foo)
valuemakeTraversals :: Name -> Q [Dec]
#

Derive traversals for each constructor in a data or newtype declaration, Traversals will be named by prefixing the constructor name with an underscore.

Example usage:

$(makeTraversals ''Foo)