lens-family-1.2.2: Lens Families

Lens.Family2.State.Strict

Description

Lenses allow you to use fields of the state of a state monad as if they were variables in an imperative language. use is used to retrieve the value of a variable, and .= and %= allow you to set and modify a variable. C-style compound assignments are also provided.

Synopsis

# Documentation

zoom :: Monad m => LensLike' (Zooming m c) a b -> StateT b m c -> StateT a m c #

zoom :: Monad m => Lens' a b -> StateT b m c -> StateT a m c


Lift a stateful operation on a field to a stateful operation on the whole state. This is a good way to call a "subroutine" that only needs access to part of the state.

zoom :: (Monoid c, Monad m) => Traversal' a b -> StateT b m c -> StateT a m c


Run the "subroutine" on each element of the traversal in turn and mconcat all the results together.

zoom :: Monad m => Traversal' a b -> StateT b m () -> StateT a m ()


Run the "subroutine" on each element the traversal in turn.

use :: MonadState a m => FoldLike b a a' b b' -> m b Source #

use :: MonadState a m => Getter a a' b b' -> m b


Retrieve a field of the state

use :: (Monoid b, MonadState a m) => Fold a a' b b' -> m b


Retrieve a monoidal summary of all the referenced fields from the state

uses :: MonadState a m => FoldLike r a a' b b' -> (b -> r) -> m r Source #

uses :: (MonadState a m, Monoid r) => Fold a a' b b' -> (b -> r) -> m r


Retrieve all the referenced fields from the state and foldMap the results together with f :: b -> r.

uses :: MonadState a m => Getter a a' b b' -> (b -> r) -> m r


Retrieve a field of the state and pass it through the function f :: b -> r.

# Re-exports

type LensLike f a a' b b' = (b -> f b') -> a -> f a' #

type LensLike' f a b = (b -> f b) -> a -> f a #

type FoldLike r a a' b b' = LensLike (Constant * r) a a' b b' #

data Constant k a b :: forall k. * -> k -> * #

Constant functor.

Instances

 MethodsliftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Constant * a c -> Constant * b d -> Bool # MethodsliftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Constant * a c -> Constant * b d -> Ordering # MethodsliftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Constant * a b) #liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Constant * a b] # MethodsliftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Constant * a b -> ShowS #liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Constant * a b] -> ShowS # Methodsbimap :: (a -> b) -> (c -> d) -> Constant * a c -> Constant * b d #first :: (a -> b) -> Constant * a c -> Constant * b c #second :: (b -> c) -> Constant * a b -> Constant * a c # Methodsfmap :: (a -> b) -> Constant * a a -> Constant * a b #(<$) :: a -> Constant * a b -> Constant * a a # Monoid a => Applicative (Constant * a) Methodspure :: a -> Constant * a a #(<*>) :: Constant * a (a -> b) -> Constant * a a -> Constant * a b #(*>) :: Constant * a a -> Constant * a b -> Constant * a b #(<*) :: Constant * a a -> Constant * a b -> Constant * a a # Methodsfold :: Monoid m => Constant * a m -> m #foldMap :: Monoid m => (a -> m) -> Constant * a a -> m #foldr :: (a -> b -> b) -> b -> Constant * a a -> b #foldr' :: (a -> b -> b) -> b -> Constant * a a -> b #foldl :: (b -> a -> b) -> b -> Constant * a a -> b #foldl' :: (b -> a -> b) -> b -> Constant * a a -> b #foldr1 :: (a -> a -> a) -> Constant * a a -> a #foldl1 :: (a -> a -> a) -> Constant * a a -> a #toList :: Constant * a a -> [a] #null :: Constant * a a -> Bool #length :: Constant * a a -> Int #elem :: Eq a => a -> Constant * a a -> Bool #maximum :: Ord a => Constant * a a -> a #minimum :: Ord a => Constant * a a -> a #sum :: Num a => Constant * a a -> a #product :: Num a => Constant * a a -> a # Methodstraverse :: Applicative f => (a -> f b) -> Constant * a a -> f (Constant * a b) #sequenceA :: Applicative f => Constant * a (f a) -> f (Constant * a a) #mapM :: Monad m => (a -> m b) -> Constant * a a -> m (Constant * a b) #sequence :: Monad m => Constant * a (m a) -> m (Constant * a a) # Eq a => Eq1 (Constant * a) MethodsliftEq :: (a -> b -> Bool) -> Constant * a a -> Constant * a b -> Bool # Ord a => Ord1 (Constant * a) MethodsliftCompare :: (a -> b -> Ordering) -> Constant * a a -> Constant * a b -> Ordering # Read a => Read1 (Constant * a) MethodsliftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Constant * a a) #liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Constant * a a] # Show a => Show1 (Constant * a) MethodsliftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Constant * a a -> ShowS #liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Constant * a a] -> ShowS # Methodscoerce :: Constant * a a -> Constant * a b Eq a => Eq (Constant k a b) Methods(==) :: Constant k a b -> Constant k a b -> Bool #(/=) :: Constant k a b -> Constant k a b -> Bool # Ord a => Ord (Constant k a b) Methodscompare :: Constant k a b -> Constant k a b -> Ordering #(<) :: Constant k a b -> Constant k a b -> Bool #(<=) :: Constant k a b -> Constant k a b -> Bool #(>) :: Constant k a b -> Constant k a b -> Bool #(>=) :: Constant k a b -> Constant k a b -> Bool #max :: Constant k a b -> Constant k a b -> Constant k a b #min :: Constant k a b -> Constant k a b -> Constant k a b # Read a => Read (Constant k a b) MethodsreadsPrec :: Int -> ReadS (Constant k a b) #readList :: ReadS [Constant k a b] #readPrec :: ReadPrec (Constant k a b) #readListPrec :: ReadPrec [Constant k a b] # Show a => Show (Constant k a b) MethodsshowsPrec :: Int -> Constant k a b -> ShowS #show :: Constant k a b -> String #showList :: [Constant k a b] -> ShowS # Monoid a => Monoid (Constant k a b) Methodsmempty :: Constant k a b #mappend :: Constant k a b -> Constant k a b -> Constant k a b #mconcat :: [Constant k a b] -> Constant k a b # type Setter a a' b b' = forall f. Identical f => LensLike f a a' b b' Source # type Setter' a b = forall f. Identical f => LensLike' f a b Source # class Applicative f => Identical f # Minimal complete definition extract Instances  Methodsextract :: Identity a -> a Identical f => Identical (Backwards * f) Methodsextract :: Backwards * f a -> a (Identical f, Identical g) => Identical (Compose * * f g) Methodsextract :: Compose * * f g a -> a data StateT s m a :: * -> (* -> *) -> * -> * # A state transformer monad parameterized by: • s - The state. • m - The inner monad. The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second. Instances  Monad m => MonadState s (StateT s m) Methodsget :: StateT s m s #put :: s -> StateT s m () #state :: (s -> (a, s)) -> StateT s m a # Methodslift :: Monad m => m a -> StateT s m a # Monad m => Monad (StateT s m) Methods(>>=) :: StateT s m a -> (a -> StateT s m b) -> StateT s m b #(>>) :: StateT s m a -> StateT s m b -> StateT s m b #return :: a -> StateT s m a #fail :: String -> StateT s m a # Functor m => Functor (StateT s m) Methodsfmap :: (a -> b) -> StateT s m a -> StateT s m b #(<$) :: a -> StateT s m b -> StateT s m a # MonadFix m => MonadFix (StateT s m) Methodsmfix :: (a -> StateT s m a) -> StateT s m a # MonadFail m => MonadFail (StateT s m) Methodsfail :: String -> StateT s m a # (Functor m, Monad m) => Applicative (StateT s m) Methodspure :: a -> StateT s m a #(<*>) :: StateT s m (a -> b) -> StateT s m a -> StateT s m b #(*>) :: StateT s m a -> StateT s m b -> StateT s m b #(<*) :: StateT s m a -> StateT s m b -> StateT s m a # MonadIO m => MonadIO (StateT s m) MethodsliftIO :: IO a -> StateT s m a # (Functor m, MonadPlus m) => Alternative (StateT s m) Methodsempty :: StateT s m a #(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #some :: StateT s m a -> StateT s m [a] #many :: StateT s m a -> StateT s m [a] # MonadPlus m => MonadPlus (StateT s m) Methodsmzero :: StateT s m a #mplus :: StateT s m a -> StateT s m a -> StateT s m a #

class Monad m => MonadState s m | m -> s #

Minimal definition is either both of get and put or just state

Minimal complete definition

Instances

type Writer w = WriterT w Identity #

A writer monad parameterized by the type w of output to accumulate.

The return function produces the output mempty, while >>= combines the outputs of the subcomputations using mappend.

class Monoid a #

The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:

• mappend mempty x = x
• mappend x mempty = x
• mappend x (mappend y z) = mappend (mappend x y) z
• mconcat = foldr mappend mempty

The method names refer to the monoid of lists under concatenation, but there are many other instances.

Some types can be viewed as a monoid in more than one way, e.g. both addition and multiplication on numbers. In such cases we often define newtypes and make those instances of Monoid, e.g. Sum and Product.

Minimal complete definition

Instances

 Methodsmconcat :: [Ordering] -> Ordering # Monoid () Methodsmempty :: () #mappend :: () -> () -> () #mconcat :: [()] -> () # Methodsmappend :: All -> All -> All #mconcat :: [All] -> All # Methodsmappend :: Any -> Any -> Any #mconcat :: [Any] -> Any # Methodsmconcat :: [IntSet] -> IntSet # Monoid [a] Methodsmempty :: [a] #mappend :: [a] -> [a] -> [a] #mconcat :: [[a]] -> [a] # Monoid a => Monoid (Maybe a) Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S." Since there is no "Semigroup" typeclass providing just mappend, we use Monoid instead. Methodsmempty :: Maybe a #mappend :: Maybe a -> Maybe a -> Maybe a #mconcat :: [Maybe a] -> Maybe a # Monoid a => Monoid (IO a) Methodsmempty :: IO a #mappend :: IO a -> IO a -> IO a #mconcat :: [IO a] -> IO a # Ord a => Monoid (Max a) Methodsmempty :: Max a #mappend :: Max a -> Max a -> Max a #mconcat :: [Max a] -> Max a # Ord a => Monoid (Min a) Methodsmempty :: Min a #mappend :: Min a -> Min a -> Min a #mconcat :: [Min a] -> Min a # Monoid a => Monoid (Identity a) Methodsmappend :: Identity a -> Identity a -> Identity a #mconcat :: [Identity a] -> Identity a # Monoid a => Monoid (Dual a) Methodsmempty :: Dual a #mappend :: Dual a -> Dual a -> Dual a #mconcat :: [Dual a] -> Dual a # Monoid (Endo a) Methodsmempty :: Endo a #mappend :: Endo a -> Endo a -> Endo a #mconcat :: [Endo a] -> Endo a # Num a => Monoid (Sum a) Methodsmempty :: Sum a #mappend :: Sum a -> Sum a -> Sum a #mconcat :: [Sum a] -> Sum a # Num a => Monoid (Product a) Methodsmappend :: Product a -> Product a -> Product a #mconcat :: [Product a] -> Product a # Monoid (First a) Methodsmempty :: First a #mappend :: First a -> First a -> First a #mconcat :: [First a] -> First a # Monoid (Last a) Methodsmempty :: Last a #mappend :: Last a -> Last a -> Last a #mconcat :: [Last a] -> Last a # Monoid (IntMap a) Methodsmappend :: IntMap a -> IntMap a -> IntMap a #mconcat :: [IntMap a] -> IntMap a # Ord a => Monoid (Set a) Methodsmempty :: Set a #mappend :: Set a -> Set a -> Set a #mconcat :: [Set a] -> Set a # Monoid b => Monoid (a -> b) Methodsmempty :: a -> b #mappend :: (a -> b) -> (a -> b) -> a -> b #mconcat :: [a -> b] -> a -> b # (Monoid a, Monoid b) => Monoid (a, b) Methodsmempty :: (a, b) #mappend :: (a, b) -> (a, b) -> (a, b) #mconcat :: [(a, b)] -> (a, b) # Monoid (Proxy k s) Methodsmempty :: Proxy k s #mappend :: Proxy k s -> Proxy k s -> Proxy k s #mconcat :: [Proxy k s] -> Proxy k s # Ord k => Monoid (Map k v) Methodsmempty :: Map k v #mappend :: Map k v -> Map k v -> Map k v #mconcat :: [Map k v] -> Map k v # (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) Methodsmempty :: (a, b, c) #mappend :: (a, b, c) -> (a, b, c) -> (a, b, c) #mconcat :: [(a, b, c)] -> (a, b, c) # Alternative f => Monoid (Alt * f a) Methodsmempty :: Alt * f a #mappend :: Alt * f a -> Alt * f a -> Alt * f a #mconcat :: [Alt * f a] -> Alt * f a # Monoid a => Monoid (Constant k a b) Methodsmempty :: Constant k a b #mappend :: Constant k a b -> Constant k a b -> Constant k a b #mconcat :: [Constant k a b] -> Constant k a b # (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) Methodsmempty :: (a, b, c, d) #mappend :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) #mconcat :: [(a, b, c, d)] -> (a, b, c, d) # (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) Methodsmempty :: (a, b, c, d, e) #mappend :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) #mconcat :: [(a, b, c, d, e)] -> (a, b, c, d, e) #