Cabal-3.2.0.0: A framework for packaging Haskell software
Safe HaskellNone
LanguageHaskell2010

Distribution.Compat.Lens

Description

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.

Synopsis

Types

type Lens s t a b = forall f. Functor f => LensLike f s t a b Source #

type Lens' s a = Lens s s a a Source #

type Traversal s t a b = forall f. Applicative f => LensLike f s t a b Source #

type Traversal' s a = Traversal s s a a Source #

LensLike

type LensLike f s t a b = (a -> f b) -> s -> f t Source #

type LensLike' f s a = (a -> f a) -> s -> f s Source #

rank-1 types

type Getting r s a = LensLike (Const r) s s a a Source #

type AGetter s a = LensLike (Const a) s s a a Source #

type ASetter s t a b = LensLike Identity s t a b Source #

type ALens s t a b = LensLike (Pretext a b) s t a b Source #

type ALens' s a = ALens s s a a Source #

Getter

view :: Getting a s a -> s -> a Source #

use :: MonadState s m => Getting a s a -> m a Source #

getting :: (s -> a) -> Getting r s a Source #

>>> (3 :: Int) ^. getting (+2) . getting show
"5"

Since: Cabal-2.4

Setter

set :: ASetter s t a b -> b -> s -> t Source #

over :: ASetter s t a b -> (a -> b) -> s -> t Source #

Fold

toDListOf :: Getting (DList a) s a -> s -> DList a Source #

toListOf :: Getting (DList a) s a -> s -> [a] Source #

toSetOf :: Getting (Set a) s a -> s -> Set a Source #

Lens

cloneLens :: Functor f => ALens s t a b -> LensLike f s t a b Source #

aview :: ALens s t a b -> s -> a Source #

Common lenses

_1 :: Lens (a, c) (b, c) a b Source #

_2 :: Lens (c, a) (c, b) a b Source #

Operators

(&) :: a -> (a -> b) -> b infixl 1 Source #

& is a reverse application operator

(^.) :: s -> Getting a s a -> a infixl 8 Source #

(.~) :: ASetter s t a b -> b -> s -> t infixr 4 Source #

(?~) :: ASetter s t a (Maybe b) -> b -> s -> t infixr 4 Source #

(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 Source #

(.=) :: MonadState s m => ASetter s s a b -> b -> m () infixr 4 Source #

(?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m () infixr 4 Source #

(%=) :: MonadState s m => ASetter s s a b -> (a -> b) -> m () infixr 4 Source #

(^#) :: s -> ALens s t a b -> a infixl 8 Source #

(#~) :: ALens s t a b -> b -> s -> t infixr 4 Source #

(#%~) :: ALens s t a b -> (a -> b) -> s -> t infixr 4 Source #

Internal Comonads

data Pretext a b t Source #

lens variant is also parametrised by profunctor.

Constructors

Pretext 

Fields

Instances

Instances details
Functor (Pretext a b) # 
Instance details

Defined in Distribution.Compat.Lens

Methods

fmap :: (a0 -> b0) -> Pretext a b a0 -> Pretext a b b0 Source #

(<$) :: a0 -> Pretext a b b0 -> Pretext a b a0 Source #

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: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))
{--}
...

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