| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
ZIO.Trans
Synopsis
- newtype EIO e a = EIO {}
- newtype ZIO r e a = ZIO {}
- type UEIO a = EIO Void a
- type URIO r a = ZIO r Void a
- type UZIO a = ZIO Void Void a
- type Task a = ZIO Void SomeNonPseudoException a
- type RIO r a = ZIO r SomeNonPseudoException a
- elift :: IO a -> EIO SomeNonPseudoException a
- ezlift :: forall r e a. EIO e a -> ZIO r e a
- zlift :: IO a -> ZIO r SomeNonPseudoException a
- uelift :: forall e a. UIO a -> EIO e a
- uzlift :: forall r e a. UIO a -> ZIO r e a
- euUnlift :: UEIO a -> UIO a
- zuUnlift :: UZIO a -> UIO a
- mapEError :: (e -> e') -> EIO e a -> EIO e' a
- mapZError :: (e -> e') -> ZIO r e a -> ZIO r e' a
- runEIO :: MonadIO m => EIO e a -> (e -> m a) -> m a
- runZIO :: MonadIO m => ZIO r e a -> r -> (e -> m a) -> m a
- withEIO :: (e -> e') -> EIO e a -> EIO e' a
- withZIO :: r -> (e -> e') -> ZIO r e a -> ZIO r e' a
- module Control.Monad.Except
- guard :: Alternative f => Bool -> f ()
- join :: Monad m => m (m a) -> m a
- class Applicative m => Monad (m :: Type -> Type) where
- class Functor (f :: Type -> Type) where
- class Monad m => MonadFix (m :: Type -> Type) where
- mfix :: (a -> m a) -> m a
- class Monad m => MonadFail (m :: Type -> Type) where
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- class Monad m => MonadIO (m :: Type -> Type) where
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- unless :: Applicative f => Bool -> f () -> f ()
- replicateM_ :: Applicative m => Int -> m a -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- forever :: Applicative f => f a -> f b
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- fix :: (a -> a) -> a
- void :: Functor f => f a -> f ()
- ap :: Monad m => m (a -> b) -> m a -> m b
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- when :: Applicative f => Bool -> f () -> f ()
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- class MonadTrans (t :: (Type -> Type) -> Type -> Type)
- asks :: MonadReader r m => (r -> a) -> m a
- class Monad m => MonadReader r (m :: Type -> Type) | m -> r where
- newtype ReaderT r (m :: Type -> Type) a = ReaderT {
- runReaderT :: r -> m a
- type Reader r = ReaderT r Identity
- runReader :: Reader r a -> r -> a
- mapReader :: (a -> b) -> Reader r a -> Reader r b
- withReader :: (r' -> r) -> Reader r a -> Reader r' a
- mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
- withReaderT :: forall r' r (m :: Type -> Type) a. (r' -> r) -> ReaderT r m a -> ReaderT r' m a
- fork :: Unexceptional m => UIO () -> m ThreadId
- forkFinally :: Unexceptional m => UIO a -> (Either PseudoException a -> UIO ()) -> m ThreadId
- bracket :: Unexceptional m => UIO a -> (a -> UIO ()) -> (a -> UIO c) -> m c
- unsafeFromIO :: Unexceptional m => IO a -> m a
- runEitherIO :: Exception e => UIO (Either e a) -> IO a
- fromIO' :: (Exception e, Unexceptional m) => (SomeNonPseudoException -> e) -> IO a -> m (Either e a)
- data PseudoException
- data ProgrammerError
- = TypeError TypeError
- | ArithException ArithException
- | ArrayException ArrayException
- | AssertionFailed AssertionFailed
- | ErrorCall ErrorCall
- | NestedAtomically NestedAtomically
- | NoMethodError NoMethodError
- | PatternMatchFail PatternMatchFail
- | RecConError RecConError
- | RecSelError RecSelError
- | RecUpdError RecSelError
- data ExternalError
- data SomeNonPseudoException
- data UIO a
- class Monad m => Unexceptional (m :: Type -> Type)
- newtype ChildThreadError = ChildThreadError PseudoException
- data UIO a
- run :: MonadIO m => UIO a -> m a
- fromIO :: forall (m :: Type -> Type) a. Unexceptional m => IO a -> ExceptT SomeNonPseudoException m a
Documentation
Corresponds to IO[E, A] in Scala
type RIO r a = ZIO r SomeNonPseudoException a Source #
module Control.Monad.Except
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative computations. Defined by
guard True =pure() guard False =empty
Examples
Common uses of guard include conditionally signaling an error in
an error monad and conditionally rejecting the current choice in an
Alternative-based parser.
As an example of signaling an error in the error monad Maybe,
consider a safe division function safeDiv x y that returns
Nothing when the denominator y is zero and otherwise. For example:Just (x `div`
y)
>>> safeDiv 4 0 Nothing >>> safeDiv 4 2 Just 2
A definition of safeDiv using guards, but not guard:
safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0 = Just (x `div` y)
| otherwise = Nothing
A definition of safeDiv using guard and Monad do-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
join :: Monad m => m (m a) -> m a #
The join function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
'' can be understood as the join bssdo expression
do bs <- bss bs
Examples
A common use of join is to run an IO computation returned from
an STM transaction, since STM transactions
can't perform IO directly. Recall that
atomically :: STM a -> IO a
is used to run STM transactions atomically. So, by
specializing the types of atomically and join to
atomically:: STM (IO b) -> IO (IO b)join:: IO (IO b) -> IO b
we can compose them as
join.atomically:: STM (IO b) -> IO b
class Applicative m => Monad (m :: Type -> Type) where #
The Monad class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad should satisfy the following:
- Left identity
returna>>=k = k a- Right identity
m>>=return= m- Associativity
m>>=(\x -> k x>>=h) = (m>>=k)>>=h
Furthermore, the Monad and Applicative operations should relate as follows:
The above laws imply:
and that pure and (<*>) satisfy the applicative functor laws.
The instances of Monad for lists, Maybe and IO
defined in the Prelude satisfy these laws.
Minimal complete definition
Methods
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as ' can be understood as the >>= bsdo expression
do a <- as bs a
(>>) :: m a -> m b -> m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
'as ' can be understood as the >> bsdo expression
do as bs
Inject a value into the monadic type.
Instances
| Monad [] | Since: base-2.1 |
| Monad Maybe | Since: base-2.1 |
| Monad IO | Since: base-2.1 |
| Monad Par1 | Since: base-4.9.0.0 |
| Monad Min | Since: base-4.9.0.0 |
| Monad Max | Since: base-4.9.0.0 |
| Monad First | Since: base-4.9.0.0 |
| Monad Last | Since: base-4.9.0.0 |
| Monad Option | Since: base-4.9.0.0 |
| Monad STM | Since: base-4.3.0.0 |
| Monad ReadP | Since: base-2.1 |
| Monad NonEmpty | Since: base-4.9.0.0 |
| Monad UIO | |
| Monad P | Since: base-2.1 |
| Monad (Either e) | Since: base-4.4.0.0 |
| Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
| Monad (EIO e) Source # | |
| Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
| (Monad m, Error e) => Monad (ErrorT e m) | |
| Monad m => Monad (ExceptT e m) | |
| Monad m => Monad (ReaderT r m) | |
| Monad (ZIO r e) Source # | |
| Monad ((->) r :: Type -> Type) | Since: base-2.1 |
| (Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
| (Monad f, Monad g) => Monad (Product f g) | Since: base-4.9.0.0 |
| Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
class Functor (f :: Type -> Type) where #
A type f is a Functor if it provides a function fmap which, given any types a and b
lets you apply any function from (a -> b) to turn an f a into an f b, preserving the
structure of f. Furthermore f needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap and
the first law, so you need only check that the former condition holds.
Minimal complete definition
Methods
fmap :: (a -> b) -> f a -> f b #
Using ApplicativeDo: '' can be understood as
the fmap f asdo expression
do a <- as pure (f a)
with an inferred Functor constraint.
Instances
| Functor [] | Since: base-2.1 |
| Functor Maybe | Since: base-2.1 |
| Functor IO | Since: base-2.1 |
| Functor Par1 | Since: base-4.9.0.0 |
| Functor Min | Since: base-4.9.0.0 |
| Functor Max | Since: base-4.9.0.0 |
| Functor First | Since: base-4.9.0.0 |
| Functor Last | Since: base-4.9.0.0 |
| Functor Option | Since: base-4.9.0.0 |
| Functor Handler | Since: base-4.6.0.0 |
| Functor STM | Since: base-4.3.0.0 |
| Functor ReadP | Since: base-2.1 |
| Functor NonEmpty | Since: base-4.9.0.0 |
| Functor UIO | |
| Functor P | Since: base-4.8.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| Functor (Either a) | Since: base-3.0 |
| Functor (V1 :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Functor ((,) a) | Since: base-2.1 |
| Functor (Arg a) | Since: base-4.9.0.0 |
| Functor (EIO e) Source # | |
| Functor f => Functor (Rec1 f) | Since: base-4.9.0.0 |
| Functor (URec Char :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Double :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Float :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Int :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Word :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
| Functor ((,,) a b) | Since: base-4.14.0.0 |
| Functor m => Functor (ErrorT e m) | |
| Functor m => Functor (ExceptT e m) | |
| Functor m => Functor (ReaderT r m) | |
| Functor (ZIO r e) Source # | |
| Functor ((->) r :: Type -> Type) | Since: base-2.1 |
| Functor (K1 i c :: Type -> Type) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :+: g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :*: g) | Since: base-4.9.0.0 |
| Functor ((,,,) a b c) | Since: base-4.14.0.0 |
| (Functor f, Functor g) => Functor (Product f g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Sum f g) | Since: base-4.9.0.0 |
| Functor f => Functor (M1 i c f) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :.: g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Compose f g) | Since: base-4.9.0.0 |
class Monad m => MonadFix (m :: Type -> Type) where #
Monads having fixed points with a 'knot-tying' semantics.
Instances of MonadFix should satisfy the following laws:
- Purity
mfix(return. h) =return(fixh)- Left shrinking (or Tightening)
mfix(\x -> a >>= \y -> f x y) = a >>= \y ->mfix(\x -> f x y)- Sliding
, for strictmfix(liftMh . f) =liftMh (mfix(f . h))h.- Nesting
mfix(\x ->mfix(\y -> f x y)) =mfix(\x -> f x x)
This class is used in the translation of the recursive do notation
supported by GHC and Hugs.
Methods
Instances
| MonadFix [] | Since: base-2.1 |
Defined in Control.Monad.Fix | |
| MonadFix Maybe | Since: base-2.1 |
Defined in Control.Monad.Fix | |
| MonadFix IO | Since: base-2.1 |
Defined in Control.Monad.Fix | |
| MonadFix Par1 | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix Min | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| MonadFix Max | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| MonadFix First | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| MonadFix Last | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| MonadFix Option | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| MonadFix First | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix Last | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix Dual | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix Sum | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix Product | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix Down | Since: base-4.12.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix NonEmpty | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix UIO | |
Defined in UnexceptionalIO | |
| MonadFix (Either e) | Since: base-4.3.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix (ST s) | Since: base-2.1 |
Defined in Control.Monad.Fix | |
| MonadFix (EIO e) Source # | |
| MonadFix f => MonadFix (Rec1 f) | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix f => MonadFix (Ap f) | Since: base-4.12.0.0 |
Defined in Control.Monad.Fix | |
| MonadFix f => MonadFix (Alt f) | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
| (MonadFix m, Error e) => MonadFix (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
| MonadFix m => MonadFix (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
| MonadFix m => MonadFix (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| MonadFix (ZIO r e) Source # | |
| MonadFix ((->) r :: Type -> Type) | Since: base-2.1 |
Defined in Control.Monad.Fix | |
| (MonadFix f, MonadFix g) => MonadFix (f :*: g) | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
| (MonadFix f, MonadFix g) => MonadFix (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
| MonadFix f => MonadFix (M1 i c f) | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
class Monad m => MonadFail (m :: Type -> Type) where #
When a value is bound in do-notation, the pattern on the left
hand side of <- might not match. In this case, this class
provides a function to recover.
A Monad without a MonadFail instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat).
Instances of MonadFail should satisfy the following law: fail s should
be a left zero for >>=,
fail s >>= f = fail s
If your Monad is also MonadPlus, a popular definition is
fail _ = mzero
Since: base-4.9.0.0
Instances
| MonadFail [] | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
| MonadFail Maybe | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
| MonadFail IO | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
| MonadFail ReadP | Since: base-4.9.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| MonadFail P | Since: base-4.9.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| (Monad m, Error e) => MonadFail (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
| MonadFail m => MonadFail (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
| MonadFail m => MonadFail (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_.
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_.
class Monad m => MonadIO (m :: Type -> Type) where #
Monads in which IO computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Instances
| MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
| (Error e, MonadIO m) => MonadIO (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
| MonadIO m => MonadIO (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
| MonadIO m => MonadIO (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
replicateM_ :: Applicative m => Int -> m a -> m () #
Like replicateM, but discards the result.
replicateM :: Applicative m => Int -> m a -> m [a] #
performs the action replicateM n actn times,
gathering the results.
Using ApplicativeDo: '' can be understood as
the replicateM 5 asdo expression
do a1 <- as a2 <- as a3 <- as a4 <- as a5 <- as pure [a1,a2,a3,a4,a5]
Note the Applicative constraint.
foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () #
Like foldM, but discards the result.
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
The foldM function is analogous to foldl, except that its result is
encapsulated in a monad. Note that foldM works from left-to-right over
the list arguments. This could be an issue where ( and the `folded
function' are not commutative.>>)
foldM f a1 [x1, x2, ..., xm] == do a2 <- f a1 x1 a3 <- f a2 x2 ... f am xm
If right-to-left evaluation is required, the input list should be reversed.
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
The mapAndUnzipM function maps its first argument over a list, returning
the result as a pair of lists. This function is mainly used with complicated
data structures or a state monad.
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Using ApplicativeDo: '' can be understood as the
pseudo-forever asdo expression
do as as ..
with as repeating.
Examples
A common use of forever is to process input from network sockets,
Handles, and channels
(e.g. MVar and
Chan).
For example, here is how we might implement an echo
server, using
forever both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever$ do client <- accept socketforkFinally(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever$ hGetLine client >>= hPutStrLn client
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right composition of Kleisli arrows.
'(bs ' can be understood as the >=> cs) ado expression
do b <- bs a cs b
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter function.
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence.
As of base 4.8.0.0, sequence_ is just sequenceA_, specialized
to Monad.
is the least fixed point of the function fix ff,
i.e. the least defined x such that f x = x.
For example, we can write the factorial function using direct recursion as
>>>let fac n = if n <= 1 then 1 else n * fac (n-1) in fac 5120
This uses the fact that Haskell’s let introduces recursive bindings. We can
rewrite this definition using fix,
>>>fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5120
Instead of making a recursive call, we introduce a dummy parameter rec;
when used within fix, this parameter then refers to fix’s argument, hence
the recursion is reintroduced.
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Using ApplicativeDo: '' can be understood as the
void asdo expression
do as pure ()
with an inferred Functor constraint.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an
with unit, resulting in an Either Int Int:Either Int ()
>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]>>>void $ mapM print [1,2]1 2
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2).
liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2).
liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2).
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r #
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging if the Boolean value debug
is True, and otherwise do nothing.
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=, but with the arguments interchanged.
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>)
Instances
| MonadPlus [] | Since: base-2.1 |
| MonadPlus Maybe | Since: base-2.1 |
| MonadPlus IO | Since: base-4.9.0.0 |
| MonadPlus Option | Since: base-4.9.0.0 |
| MonadPlus STM | Since: base-4.3.0.0 |
| MonadPlus ReadP | Since: base-2.1 |
| MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
| MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
| (Monad m, Error e) => MonadPlus (ErrorT e m) | |
| (Monad m, Monoid e) => MonadPlus (ExceptT e m) | |
| MonadPlus m => MonadPlus (ReaderT r m) | |
| (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (Product f g) | Since: base-4.9.0.0 |
| MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |
class MonadTrans (t :: (Type -> Type) -> Type -> Type) #
The class of monad transformers. Instances should satisfy the
following laws, which state that lift is a monad transformation:
Minimal complete definition
Instances
| MonadTrans (ErrorT e) | |
Defined in Control.Monad.Trans.Error | |
| MonadTrans (ExceptT e) | |
Defined in Control.Monad.Trans.Except | |
| MonadTrans (ReaderT r) | |
Defined in Control.Monad.Trans.Reader | |
Arguments
| :: MonadReader r m | |
| => (r -> a) | The selector function to apply to the environment. |
| -> m a |
Retrieves a function of the current environment.
class Monad m => MonadReader r (m :: Type -> Type) | m -> r where #
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r is a simple reader monad.
See the instance declaration below.
Methods
Retrieves the monad environment.
Arguments
| :: (r -> r) | The function to modify the environment. |
| -> m a |
|
| -> m a |
Executes a computation in a modified environment.
Arguments
| :: (r -> a) | The selector function to apply to the environment. |
| -> m a |
Retrieves a function of the current environment.
Instances
| MonadReader r m => MonadReader r (MaybeT m) | |
| MonadReader r m => MonadReader r (ListT m) | |
| MonadReader r (ZIO r e) Source # | |
| Monad m => MonadReader r (ReaderT r m) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| MonadReader r m => MonadReader r (IdentityT m) | |
| MonadReader r m => MonadReader r (ExceptT e m) | Since: mtl-2.2 |
| (Error e, MonadReader r m) => MonadReader r (ErrorT e m) | |
| MonadReader r ((->) r :: Type -> Type) | |
| MonadReader r' m => MonadReader r' (ContT r m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
newtype ReaderT r (m :: Type -> Type) a #
The reader monad transformer, which adds a read-only environment to the given monad.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
Constructors
| ReaderT | |
Fields
| |
Instances
| Monad m => MonadReader r (ReaderT r m) | |
| MonadError e m => MonadError e (ReaderT r m) | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> ReaderT r m a # catchError :: ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a # | |
| MonadTrans (ReaderT r) | |
Defined in Control.Monad.Trans.Reader | |
| Monad m => Monad (ReaderT r m) | |
| Functor m => Functor (ReaderT r m) | |
| MonadFix m => MonadFix (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| MonadFail m => MonadFail (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| Contravariant m => Contravariant (ReaderT r m) | |
| MonadZip m => MonadZip (ReaderT r m) | |
| MonadIO m => MonadIO (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| Alternative m => Alternative (ReaderT r m) | |
| MonadPlus m => MonadPlus (ReaderT r m) | |
type Reader r = ReaderT r Identity #
The parameterizable reader monad.
Computations are functions of a shared environment.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
Arguments
| :: Reader r a | A |
| -> r | An initial environment. |
| -> a |
Runs a Reader and extracts the final value from it.
(The inverse of reader.)
Arguments
| :: (r' -> r) | The function to modify the environment. |
| -> Reader r a | Computation to run in the modified environment. |
| -> Reader r' a |
Execute a computation in a modified environment
(a specialization of withReaderT).
runReader(withReaderf m) =runReaderm . f
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b #
Transform the computation inside a ReaderT.
runReaderT(mapReaderTf m) = f .runReaderTm
Arguments
| :: forall r' r (m :: Type -> Type) a. (r' -> r) | The function to modify the environment. |
| -> ReaderT r m a | Computation to run in the modified environment. |
| -> ReaderT r' m a |
Execute a computation in a modified environment
(a more general version of local).
runReaderT(withReaderTf m) =runReaderTm . f
fork :: Unexceptional m => UIO () -> m ThreadId #
Mirrors forkIO, but re-throws errors to the parent thread
- Ignores manual thread kills, since those are on purpose.
- Re-throws async exceptions (
SomeAsyncException) as is. - Re-throws
ExitCodeas is in an attempt to exit with the requested code. - Wraps synchronous
PseudoExceptionin asyncChildThreadError.
forkFinally :: Unexceptional m => UIO a -> (Either PseudoException a -> UIO ()) -> m ThreadId #
Mirrors forkFinally, but since the body is UIO,
the thread must terminate successfully or because of PseudoException
bracket :: Unexceptional m => UIO a -> (a -> UIO ()) -> (a -> UIO c) -> m c #
When you're doing resource handling, PseudoException matters.
You still need to use the bracket pattern to handle cleanup.
unsafeFromIO :: Unexceptional m => IO a -> m a #
You promise there are no exceptions but PseudoException thrown by this IO action
Arguments
| :: (Exception e, Unexceptional m) | |
| => (SomeNonPseudoException -> e) | Default if an unexpected exception occurs |
| -> IO a | |
| -> m (Either e a) |
Catch any e in an IO action, with a default mapping for
unexpected cases
data PseudoException #
Not everything handled by the exception system is a run-time error you can handle. This is the class of unrecoverable pseudo-exceptions.
Additionally, except for ExitCode any of these pseudo-exceptions
you could never guarantee to have caught. Since they can come
from anywhere at any time, we could never guarentee that UIO does
not contain them.
Constructors
| ProgrammerError ProgrammerError | Mistakes programmers make |
| ExternalError ExternalError | Errors thrown by the runtime |
| Exit ExitCode | Process exit requests |
Instances
| Show PseudoException | |
Defined in UnexceptionalIO Methods showsPrec :: Int -> PseudoException -> ShowS # show :: PseudoException -> String # showList :: [PseudoException] -> ShowS # | |
| Exception PseudoException | |
Defined in UnexceptionalIO Methods toException :: PseudoException -> SomeException # | |
data ProgrammerError #
Constructors
Instances
| Show ProgrammerError | |
Defined in UnexceptionalIO Methods showsPrec :: Int -> ProgrammerError -> ShowS # show :: ProgrammerError -> String # showList :: [ProgrammerError] -> ShowS # | |
| Exception ProgrammerError | |
Defined in UnexceptionalIO Methods toException :: ProgrammerError -> SomeException # | |
data ExternalError #
Pseudo-exceptions thrown by the runtime environment
Constructors
Instances
| Show ExternalError | |
Defined in UnexceptionalIO Methods showsPrec :: Int -> ExternalError -> ShowS # show :: ExternalError -> String # showList :: [ExternalError] -> ShowS # | |
| Exception ExternalError | |
Defined in UnexceptionalIO Methods toException :: ExternalError -> SomeException # fromException :: SomeException -> Maybe ExternalError # displayException :: ExternalError -> String # | |
data SomeNonPseudoException #
Every SomeException but PseudoException
Instances
| Show SomeNonPseudoException | |
Defined in UnexceptionalIO Methods showsPrec :: Int -> SomeNonPseudoException -> ShowS # show :: SomeNonPseudoException -> String # showList :: [SomeNonPseudoException] -> ShowS # | |
| Exception SomeNonPseudoException | |
Defined in UnexceptionalIO | |
Like IO, but throws only PseudoException
Instances
| Monad UIO | |
| Functor UIO | |
| MonadFix UIO | |
Defined in UnexceptionalIO | |
| Applicative UIO | |
| Unexceptional UIO | |
Defined in UnexceptionalIO | |
class Monad m => Unexceptional (m :: Type -> Type) #
Monads in which UIO computations may be embedded
Minimal complete definition
Instances
| Unexceptional IO | |
Defined in UnexceptionalIO | |
| Unexceptional UIO | |
Defined in UnexceptionalIO | |
| Unexceptional (EIO e) Source # | |
| Unexceptional (ZIO r e) Source # | |
newtype ChildThreadError #
Async signal that a child thread ended due to non-async PseudoException
Constructors
| ChildThreadError PseudoException |
Instances
| Show ChildThreadError | |
Defined in UnexceptionalIO Methods showsPrec :: Int -> ChildThreadError -> ShowS # show :: ChildThreadError -> String # showList :: [ChildThreadError] -> ShowS # | |
| Exception ChildThreadError | |
Defined in UnexceptionalIO Methods toException :: ChildThreadError -> SomeException # | |
Like IO, but throws only PseudoException
Instances
| Monad UIO | |
| Functor UIO | |
| MonadFix UIO | |
Defined in UnexceptionalIO | |
| Applicative UIO | |
| Unexceptional UIO | |
Defined in UnexceptionalIO | |
fromIO :: forall (m :: Type -> Type) a. Unexceptional m => IO a -> ExceptT SomeNonPseudoException m a #
Catch any exception but PseudoException in an IO action