HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleCabal-syntax-3.12.1.0Haskell2010

Distribution.Compat.Lens

This module provides very basic lens functionality, without extra dependencies.

For the documentation of the combinators see lens package. This module uses the same vocabulary.

  • 12 types
  • 23 values

Types

4 declarations

LensLike

rank-1 types

Getter

3 declarations
valuegetting :: (s -> a) -> Getting r s a
#
Example1 expression
(3 :: Int) ^. getting (+2) . getting show"5"

Setter

2 declarations

Fold

3 declarations

Lens

2 declarations

Common lenses

2 declarations

Operators

11 declarations
value(&) :: a -> (a -> b) -> b
#

& is a reverse application operator

value(%~) :: ASetter s t a b -> (a -> b) -> s -> t
#
value(^#) :: s -> ALens s t a b -> a
#
value(#~) :: ALens s t a b -> b -> s -> t
#
value(#%~) :: ALens s t a b -> (a -> b) -> s -> t
#

Internal Comonads

1 declaration

Cabal developer info

0 declarations

We cannot depend on template-haskell, because Cabal is a boot library. This fact makes defining optics a manual task. Here is a small recipe to make the process less tedious.

First start a repl

cabal new-repl Cabal-tests:hackage-tests

Because --extra-package isn't yet implemented, we use a test-suite with generics-sop dependency.

In the repl, we load a helper script:

:l ../generics-sop-lens.hs

Now we are set up to derive lenses!

:m +Distribution.Types.SourceRepo
putStr $ genericLenses (Proxy :: Proxy SourceRepo)
repoKind :: Lens' SourceRepo RepoKind
repoKind f s = fmap (\x -> s { T.repoKind = x }) (f (T.repoKind s))
{-# INLINE repoKind #-}
...

Note: You may need to adjust type-aliases, e.g. String to FilePath.