constrained-monads-0.1.0.0: Typeclasses and instances for monads with constraints.

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Constrained.State

Description

This module duplicates the Control.Monad.State module from mtl for monads with constraints.

Synopsis

Documentation

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

A class for monads with state.

Minimal complete definition

state

Associated Types

type StateSuitable m a :: Constraint Source #

Methods

get :: StateSuitable m s => m s Source #

Return the state from the internals of the monad.

put :: (StateSuitable m (), StateSuitable m s) => s -> m () Source #

Replace the state inside the monad.

state :: (StateSuitable m a, StateSuitable m s) => (s -> (a, s)) -> m a Source #

Embed a simple state action in the monad.

Instances

MonadState s m => MonadState s (MaybeT m) Source # 

Associated Types

type StateSuitable (MaybeT m :: * -> *) a :: Constraint Source #

Methods

get :: MaybeT m s Source #

put :: s -> MaybeT m () Source #

state :: (StateSuitable (MaybeT m) a, StateSuitable (MaybeT m) s) => (s -> (a, s)) -> MaybeT m a Source #

MonadState s m => MonadState s (ExceptT e m) Source # 

Associated Types

type StateSuitable (ExceptT e m :: * -> *) a :: Constraint Source #

Methods

get :: ExceptT e m s Source #

put :: s -> ExceptT e m () Source #

state :: (StateSuitable (ExceptT e m) a, StateSuitable (ExceptT e m) s) => (s -> (a, s)) -> ExceptT e m a Source #

MonadState s m => MonadState s (IdentityT * m) Source # 

Associated Types

type StateSuitable (IdentityT * m :: * -> *) a :: Constraint Source #

Methods

get :: IdentityT * m s Source #

put :: s -> IdentityT * m () Source #

state :: (StateSuitable (IdentityT * m) a, StateSuitable (IdentityT * m) s) => (s -> (a, s)) -> IdentityT * m a Source #

Monad m => MonadState s (StateT s m) Source # 

Associated Types

type StateSuitable (StateT s m :: * -> *) a :: Constraint Source #

Methods

get :: StateT s m s Source #

put :: s -> StateT s m () Source #

state :: (StateSuitable (StateT s m) a, StateSuitable (StateT s m) s) => (s -> (a, s)) -> StateT s m a Source #

Monad m => MonadState s (StateT s m) Source # 

Associated Types

type StateSuitable (StateT s m :: * -> *) a :: Constraint Source #

Methods

get :: StateT s m s Source #

put :: s -> StateT s m () Source #

state :: (StateSuitable (StateT s m) a, StateSuitable (StateT s m) s) => (s -> (a, s)) -> StateT s m a Source #

MonadState s m => MonadState s (WriterT w m) Source # 

Associated Types

type StateSuitable (WriterT w m :: * -> *) a :: Constraint Source #

Methods

get :: WriterT w m s Source #

put :: s -> WriterT w m () Source #

state :: (StateSuitable (WriterT w m) a, StateSuitable (WriterT w m) s) => (s -> (a, s)) -> WriterT w m a Source #

MonadState s m => MonadState s (ReaderT * r m) Source # 

Associated Types

type StateSuitable (ReaderT * r m :: * -> *) a :: Constraint Source #

Methods

get :: ReaderT * r m s Source #

put :: s -> ReaderT * r m () Source #

state :: (StateSuitable (ReaderT * r m) a, StateSuitable (ReaderT * r m) s) => (s -> (a, s)) -> ReaderT * r m a Source #

(MonadState s m, Suitable m r) => MonadState s (ContT * r m) Source # 

Associated Types

type StateSuitable (ContT * r m :: * -> *) a :: Constraint Source #

Methods

get :: ContT * r m s Source #

put :: s -> ContT * r m () Source #

state :: (StateSuitable (ContT * r m) a, StateSuitable (ContT * r m) s) => (s -> (a, s)) -> ContT * r m a Source #

newtype 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.

Constructors

StateT 

Fields

Instances

MonadError e m => MonadError e (StateT s m) Source # 

Associated Types

type SuitableError (StateT s m :: * -> *) a :: Constraint Source #

Methods

throwError :: SuitableError (StateT s m) a => e -> StateT s m a Source #

catchError :: SuitableError (StateT s m) a => StateT s m a -> (e -> StateT s m a) -> StateT s m a Source #

MonadReader r m => MonadReader r (StateT s m) Source # 

Associated Types

type ReaderSuitable (StateT s m :: * -> *) a :: Constraint Source #

Methods

ask :: StateT s m r Source #

local :: (ReaderSuitable (StateT s m) a, ReaderSuitable (StateT s m) r) => (r -> r) -> StateT s m a -> StateT s m a Source #

reader :: (ReaderSuitable (StateT s m) r, ReaderSuitable (StateT s m) a) => (r -> a) -> StateT s m a Source #

Monad m => MonadState s (StateT s m) Source # 

Associated Types

type StateSuitable (StateT s m :: * -> *) a :: Constraint Source #

Methods

get :: StateT s m s Source #

put :: s -> StateT s m () Source #

state :: (StateSuitable (StateT s m) a, StateSuitable (StateT s m) s) => (s -> (a, s)) -> StateT s m a Source #

MonadWriter w m => MonadWriter w (StateT s m) Source # 

Associated Types

type WriterSuitable (StateT s m :: * -> *) a :: Constraint Source #

Methods

writer :: WriterSuitable (StateT s m) a => (a, w) -> StateT s m a Source #

tell :: w -> StateT s m () Source #

listenC :: WriterSuitable (StateT s m) b => (a -> w -> b) -> StateT s m a -> StateT s m b Source #

passC :: WriterSuitable (StateT s m) a => (a -> w -> w) -> StateT s m a -> StateT s m a Source #

MonadTrans (StateT s) 

Methods

lift :: Monad m => m a -> StateT s m a #

MonadTrans (StateT r) Source # 

Associated Types

type SuitableLift (StateT r :: (* -> *) -> * -> *) (m :: * -> *) a :: Constraint Source #

Methods

lift :: (Monad m, SuitableLift (StateT r) m a) => m a -> StateT r m a Source #

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) 

Methods

fmap :: (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) 

Methods

mfix :: (a -> StateT s m a) -> StateT s m a #

MonadFail m => MonadFail (StateT s m) 

Methods

fail :: String -> StateT s m a #

(Functor m, Monad m) => Applicative (StateT s m) 

Methods

pure :: 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) 

Methods

liftIO :: IO a -> StateT s m a #

(Functor m, MonadPlus m) => Alternative (StateT s m) 

Methods

empty :: 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) 

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

(Monad m, Alternative m) => Alternative (StateT s m) Source # 

Methods

empty :: Suitable (StateT s m) a => StateT s m a Source #

(<|>) :: Suitable (StateT s m) a => StateT s m a -> StateT s m a -> StateT s m a Source #

some :: Suitable (StateT s m) [a] => StateT s m a -> StateT s m [a] Source #

many :: Suitable (StateT s m) [a] => StateT s m a -> StateT s m [a] Source #

Monad m => Monad (StateT s m) Source # 

Methods

(>>=) :: Suitable (StateT s m) b => StateT s m a -> (a -> StateT s m b) -> StateT s m b Source #

Monad m => Applicative (StateT s m) Source # 

Methods

pure :: Suitable (StateT s m) a => a -> StateT s m a Source #

(<*>) :: Suitable (StateT s m) b => StateT s m (a -> b) -> StateT s m a -> StateT s m b Source #

(*>) :: Suitable (StateT s m) b => StateT s m a -> StateT s m b -> StateT s m b Source #

(<*) :: Suitable (StateT s m) a => StateT s m a -> StateT s m b -> StateT s m a Source #

liftA :: Suitable (StateT s m) b => (Vect xs -> b) -> AppVect (StateT s m) xs -> StateT s m b Source #

liftA2 :: Suitable (StateT s m) c => (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c Source #

liftA3 :: Suitable (StateT s m) d => (a -> b -> c -> d) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d Source #

liftA4 :: Suitable (StateT s m) e => (a -> b -> c -> d -> e) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d -> StateT s m e Source #

liftA5 :: Suitable (StateT s m) g => (a -> b -> c -> d -> e -> g) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d -> StateT s m e -> StateT s m g Source #

liftA6 :: Suitable (StateT s m) h => (a -> b -> c -> d -> e -> g -> h) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d -> StateT s m e -> StateT s m g -> StateT s m h Source #

liftA7 :: Suitable (StateT s m) i => (a -> b -> c -> d -> e -> g -> h -> i) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d -> StateT s m e -> StateT s m g -> StateT s m h -> StateT s m i Source #

liftA8 :: Suitable (StateT s m) j => (a -> b -> c -> d -> e -> g -> h -> i -> j) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d -> StateT s m e -> StateT s m g -> StateT s m h -> StateT s m i -> StateT s m j Source #

liftA9 :: Suitable (StateT s m) k => (a -> b -> c -> d -> e -> g -> h -> i -> j -> k) -> StateT s m a -> StateT s m b -> StateT s m c -> StateT s m d -> StateT s m e -> StateT s m g -> StateT s m h -> StateT s m i -> StateT s m j -> StateT s m k Source #

Functor m => Functor (StateT s m) Source # 

Associated Types

type Suitable (StateT s m :: * -> *) a :: Constraint Source #

Methods

fmap :: Suitable (StateT s m) b => (a -> b) -> StateT s m a -> StateT s m b Source #

(<$) :: Suitable (StateT s m) a => a -> StateT s m b -> StateT s m a Source #

MonadCont m => MonadCont (StateT s m) Source # 

Methods

callCC :: ((a -> StateT s m b) -> StateT s m a) -> StateT s m a Source #

MonadIO m => MonadIO (StateT s m) Source # 

Associated Types

type SuitableIO (StateT s m :: * -> *) a :: Constraint Source #

Methods

liftIO :: SuitableIO (StateT s m) a => IO a -> StateT s m a Source #

type SuitableLift (StateT r) m a Source # 
type SuitableLift (StateT r) m a = Suitable m (a, r)
type Suitable (StateT s m) a Source # 
type Suitable (StateT s m) a = Suitable m (a, s)
type SuitableError (StateT s m) a Source # 
type SuitableError (StateT s m) a = (Suitable m (a, s), SuitableError m (a, s), SuitableError m a)
type SuitableIO (StateT s m) a Source # 
type SuitableIO (StateT s m) a = (SuitableIO m a, Suitable m (a, s))
type ReaderSuitable (StateT s m) a Source # 
type ReaderSuitable (StateT s m) a = (ReaderSuitable m a, ReaderSuitable m (a, s), Suitable m (a, s))
type StateSuitable (StateT s m) a Source # 
type StateSuitable (StateT s m) a = Suitable m (a, s)
type WriterSuitable (StateT s m) a Source # 
type WriterSuitable (StateT s m) a = (WriterSuitable m a, WriterSuitable m (a, s), Suitable m (a, s))

gets :: (StateSuitable m s, MonadState s m, Suitable m b) => (s -> b) -> m b Source #

Get the state, while applying a transformation function.

modify :: (StateSuitable m (), StateSuitable m s, MonadState s m) => (s -> s) -> m () Source #

Modify the state.

modify' :: (StateSuitable m (), StateSuitable m s, MonadState s m) => (s -> s) -> m () Source #

Modify the state, strictly in the new state.