HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

ModuleCabal-syntax-3.18.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.

Contents
  1. Types
  2. LensLike
  3. rank-1 types
  4. Getter
  5. Setter
  6. Fold
  7. Lens
  8. Common lenses
  9. Operators
  10. Internal Comonads
  11. Cabal developer info
Synopsis

Types

LensLike

rank-1 types

Getter

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

Setter

Fold

Lens

Common lenses

Operators

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

Cabal developer info

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.