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
Synopsis
- type Lens
- type Lens'
- type Traversal
- type Traversal'
- type LensLike
- type LensLike'
- type Getting
- type AGetter
- type ASetter
- type ALens
- type ALens'
- value view
- value use
- value getting
- value set
- value over
- value toDListOf
- value toListOf
- value toSetOf
- value cloneLens
- value aview
- value _1
- value _2
- value &
- value ^.
- value .~
- value ?~
- value %~
- value .=
- value ?=
- value %=
- value ^#
- value #~
- value #%~
- data Pretext
- PackageCabal-syntax-3.18.1.0
- Exports35
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceLens.hs
Types
LensLike
rank-1 types
Getter
(3 :: Int) ^. getting (+2) . getting show"5"
Setter
Fold
Lens
Common lenses
Operators
& is a reverse application operator
Internal Comonads
lens variant is also parametrised by profunctor.
Constructors
PretextrunPretext :: forall (f :: Type -> Type). Functor f => (a -> f b) -> f t
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-testsBecause --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.hsNow 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.