lens-2.9: Lenses, Folds and Traversals

PortabilityRank2Types
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellNone

Control.Lens.Internal

Contents

Description

These are some of the explicit Functor instances that leak into the type signatures of Control.Lens. You shouldn't need to import this module directly, unless you are coming up with a whole new kind of "Family" and need to add instances.

Synopsis

Implementation details

data Context c d a Source

The indexed store can be used to characterize a Lens and is used by clone

Constructors

Context (d -> a) c 

Instances

(Comonad (Context c d), ~ * c d) => ComonadStore c (Context c d) 
Functor (Context c d) 
(Functor (Context c d), ~ * c d) => Comonad (Context c d) 

newtype Focusing m c a Source

Used by Zoom to zoom into StateT

Constructors

Focusing 

Fields

unfocusing :: m (c, a)
 

Instances

Monad m => Functor (Focusing m c) 
(Functor (Focusing m c), Monad m, Monoid c) => Applicative (Focusing m c) 
(MonadState s (StateT s z), MonadState t (StateT t z), Monad z) => Zoom (StateT s z) (StateT t z) (Focusing z) s t 
(MonadState s (StateT s z), MonadState t (StateT t z), Monad z) => Zoom (StateT s z) (StateT t z) (Focusing z) s t 

newtype FocusingWith w m c a Source

Used by Zoom to zoom into RWST

Constructors

FocusingWith 

Fields

unfocusingWith :: m (c, a, w)
 

Instances

Monad m => Functor (FocusingWith w m c) 
(Functor (FocusingWith w m c), Monad m, Monoid c, Monoid w) => Applicative (FocusingWith w m c) 
(MonadState s (RWST r w s z), MonadState t (RWST r w t z), Monoid w, Monad z) => Zoom (RWST r w s z) (RWST r w t z) (FocusingWith w z) s t 
(MonadState s (RWST r w s z), MonadState t (RWST r w t z), Monoid w, Monad z) => Zoom (RWST r w s z) (RWST r w t z) (FocusingWith w z) s t 

newtype FocusingPlus w k c a Source

Used by Zoom to zoom into WriterT.

Constructors

FocusingPlus 

Fields

unfocusingPlus :: k (c, w) a
 

Instances

(MonadState s (WriterT w m), MonadState t (WriterT w n), Monoid w, Zoom m n k s t) => Zoom (WriterT w m) (WriterT w n) (FocusingPlus w k) s t 
(MonadState s (WriterT w m), MonadState t (WriterT w n), Monoid w, Zoom m n k s t) => Zoom (WriterT w m) (WriterT w n) (FocusingPlus w k) s t 
Functor (k (c, w)) => Functor (FocusingPlus w k c) 
(Functor (FocusingPlus w k c), Monoid w, Applicative (k (c, w))) => Applicative (FocusingPlus w k c) 

newtype FocusingOn f k c a Source

Used by Zoom to zoom into MaybeT or ListT

Constructors

FocusingOn 

Fields

unfocusingOn :: k (f c) a
 

Instances

(MonadState s (ListT m), MonadState t (ListT n), Zoom m n k s t) => Zoom (ListT m) (ListT n) (FocusingOn [] k) s t 
Functor (k (f c)) => Functor (FocusingOn f k c) 
(Functor (FocusingOn f k c), Applicative (k (f c))) => Applicative (FocusingOn f k c) 

newtype FocusingErr e k c a Source

Used by Zoom to zoom into ErrorT

Constructors

FocusingErr 

Fields

unfocusingErr :: k (Err e c) a
 

Instances

(MonadState s (ErrorT e m), MonadState t (ErrorT e n), Error e, Zoom m n k s t) => Zoom (ErrorT e m) (ErrorT e n) (FocusingErr e k) s t 
Functor (k (Err e c)) => Functor (FocusingErr e k c) 
(Functor (FocusingErr e k c), Applicative (k (Err e c))) => Applicative (FocusingErr e k c) 

newtype Err e a Source

Make a monoid out of Either for error handling

Constructors

Err 

Fields

getErr :: Either e a
 

Instances

Monoid a => Monoid (Err e a) 

newtype FocusingMay k c a Source

Used by Zoom to zoom into ErrorT

Constructors

FocusingMay 

Fields

unfocusingMay :: k (May c) a
 

Instances

(MonadState s (MaybeT m), MonadState t (MaybeT n), Zoom m n k s t) => Zoom (MaybeT m) (MaybeT n) (FocusingMay k) s t 
Functor (k (May c)) => Functor (FocusingMay k c) 
(Functor (FocusingMay k c), Applicative (k (May c))) => Applicative (FocusingMay k c) 

newtype May a Source

Make a monoid out of Maybe for error handling

Constructors

May 

Fields

getMay :: Maybe a
 

Instances

Monoid a => Monoid (May a) 

newtype Traversed f Source

Used internally by traverseOf_ and the like.

Constructors

Traversed 

Fields

getTraversed :: f ()
 

Instances

newtype Sequenced m Source

Used internally by mapM_ and the like.

Constructors

Sequenced 

Fields

getSequenced :: m ()
 

Instances

newtype Indexing f a Source

Applicative composition of State Int with a Functor, used by indexed

Constructors

Indexing 

Fields

runIndexing :: Int -> IndexingResult f a
 

data IndexingResult f a Source

The result of Indexing

Constructors

IndexingResult (f a) !Int 

Instances

data Min a Source

Used for minimumOf

Constructors

NoMin 
Min a 

Instances

Ord a => Monoid (Min a) 

getMin :: Min a -> Maybe aSource

Obtain the minimum.

data Max a Source

Used for maximumOf

Constructors

NoMax 
Max a 

Instances

Ord a => Monoid (Max a) 

getMax :: Max a -> Maybe aSource

Obtain the maximum

newtype ElementOf f a Source

Used to find the nth element of a Traversal.

Constructors

ElementOf 

Fields

getElementOf :: Int -> ElementOfResult f a
 

Instances

Functor f => Functor (ElementOf f) 
(Functor (ElementOf f), Functor f) => Applicative (ElementOf f) 
(Functor (ElementOf f), Gettable f) => Gettable (ElementOf f)

This instance is a lie, but it is a useful lie.

data ElementOfResult f a Source

The result of trying to find the nth element of a Traversal.

Constructors

Searching !Int a 
Found !Int (f a) 
NotFound String 

Instances

newtype Bazaar c d a Source

This is used to characterize a Traversal.

a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed FunList.

http://twanvl.nl/blog/haskell/non-regular1

Mnemonically, a Bazaar holds many stores and you can easily add more.

This is a final encoding of Bazaar.

Constructors

Bazaar 

Fields

_runBazaar :: forall f. Applicative f => (c -> f d) -> f a
 

Instances

Functor (Bazaar c d) 
Functor (Bazaar c d) => Applicative (Bazaar c d) 
(Functor (Bazaar c d), ~ * c d) => Comonad (Bazaar c d) 
(Comonad (Bazaar c d), ~ * c d) => ComonadApply (Bazaar c d) 

bazaar :: Applicative f => (c -> f d) -> Bazaar c d b -> f bSource

Given an action to run for each matched pair, traverse a bazaar.

duplicateBazaar :: Bazaar c e a -> Bazaar c d (Bazaar d e a)Source

Bazaar is an indexed Comonad.

sell :: c -> Bazaar c d dSource

A trivial Bazaar.

newtype Effect m r a Source

Wrap a monadic effect with a phantom type argument.

Constructors

Effect 

Fields

getEffect :: m r
 

Instances

(Gettable (Effect m r), Monad m) => Effective m r (Effect m r) 
Functor (Effect m r) 
(Functor (Effect m r), Monad m, Monoid r) => Applicative (Effect m r) 
Functor (Effect m r) => Gettable (Effect m r) 
(MonadReader b (ReaderT b m), MonadReader a (ReaderT a m), Monad m) => Magnify (ReaderT b m) (ReaderT a m) (Effect m) b a 
(Monad m, Monoid r) => Monoid (Effect m r a) 

newtype EffectRWS w s m c a Source

Wrap a monadic effect with a phantom type argument. Used when magnifying RWST.

Constructors

EffectRWS 

Fields

getEffectRWS :: s -> m (c, s, w)
 

Instances

Functor (EffectRWS w s m c) 
(Functor (EffectRWS w s m c), Monoid c, Monoid w, Monad m) => Applicative (EffectRWS w s m c) 
Functor (EffectRWS w s m c) => Gettable (EffectRWS w s m c) 
(MonadReader b (RWST b w s m), MonadReader a (RWST a w s m), Monad m, Monoid w) => Magnify (RWST b w s m) (RWST a w s m) (EffectRWS w s m) b a 
(MonadReader b (RWST b w s m), MonadReader a (RWST a w s m), Monad m, Monoid w) => Magnify (RWST b w s m) (RWST a w s m) (EffectRWS w s m) b a 

class Functor f => Gettable f whereSource

Generalizing Const so we can apply simple Applicative transformations to it and so we can get nicer error messages

A Gettable Functor ignores its argument, which it carries solely as a phantom type parameter.

To ensure this, an instance of Gettable is required to satisfy:

id = fmap f = coerce

Methods

coerce :: f a -> f bSource

Replace the phantom type argument.

Instances

Functor (Const r) => Gettable (Const r) 
(Functor (Backwards f), Gettable f) => Gettable (Backwards f) 
Functor (Accessor r) => Gettable (Accessor r) 
(Functor (ElementOf f), Gettable f) => Gettable (ElementOf f)

This instance is a lie, but it is a useful lie.

(Functor (Indexing f), Gettable f) => Gettable (Indexing f) 
(Functor (Compose f g), Functor f, Gettable g) => Gettable (Compose f g) 
Functor (Effect m r) => Gettable (Effect m r) 
Functor (EffectRWS w s m c) => Gettable (EffectRWS w s m c) 

newtype Accessor r a Source

Used instead of Const to report

No instance of (Settable Accessor)

when the user attempts to misuse a Setter as a Getter, rather than a monolithic unification error.

Constructors

Accessor 

Fields

runAccessor :: r
 

Instances

class (Monad m, Gettable f) => Effective m r f | f -> m r whereSource

An Effective Functor ignores its argument and is isomorphic to a monad wrapped around a value.

That said, the monad is possibly rather unrelated to any Applicative structure.

Methods

effective :: Isomorphic k => k (m r) (f a)Source

Instances

ineffective :: Effective m r f => Isomorphic k => k (f a) (m r)Source

A convenient antonym that is used internally.

noEffect :: (Applicative f, Gettable f) => f aSource

The mempty equivalent for a Gettable Applicative Functor.

newtype Folding f a Source

Constructors

Folding 

Fields

getFolding :: f a
 

Instances

class Applicative f => Settable f whereSource

Anything Settable must be isomorphic to the Identity Functor.

Methods

untainted :: f a -> aSource

Instances

Settable Identity

so you can pass our a Setter into combinators from other lens libraries

Settable Mutator 
(Applicative (Backwards f), Settable f) => Settable (Backwards f)

backwards

(Applicative (Compose f g), Settable f, Settable g) => Settable (Compose f g) 

newtype Mutator a Source

Mutator is just a renamed Identity functor to give better error messages when someone attempts to use a getter as a setter.

Most user code will never need to see this type.

Constructors

Mutator 

Fields

runMutator :: a