Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- fmap :: (a -> b) -> f a -> f b
- class Monad m => MonadFix (m :: Type -> Type) where
- mfix :: (a -> m a) -> m a
- 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 :: (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 :: Unexceptional m => IO a -> ExceptT SomeNonPseudoException m a
Documentation
Corresponds to IO[E, A] in Scala
Instances
MonadReader r (ZIO r e) Source # | |
MonadError e (ZIO r e) Source # | |
Defined in ZIO.Trans throwError :: e -> ZIO r e a # catchError :: ZIO r e a -> (e -> ZIO r e a) -> ZIO r e a # | |
Monad (ZIO r e) Source # | |
Functor (ZIO r e) Source # | |
MonadFix (ZIO r e) Source # | |
Applicative (ZIO r e) Source # | |
Unexceptional (ZIO r e) Source # | |
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.
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 laws:
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.
(>>=) :: 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.
(>>) :: 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.
Inject a value into the monadic type.
Fail with a message. This operation is not part of the
mathematical definition of a monad, but is invoked on pattern-match
failure in a do
expression.
As part of the MonadFail proposal (MFP), this function is moved
to its own class MonadFail
(see Control.Monad.Fail for more
details). The definition here will be removed in a future
release.
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 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 |
(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 |
(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 #
The Functor
class is used for types that can be mapped over.
Instances of Functor
should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor
for lists, Maybe
and IO
satisfy these laws.
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 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 (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 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 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
(fix
h)- left shrinking (or tightening)
mfix
(\x -> a >>= \y -> f x y) = a >>= \y ->mfix
(\x -> f x y)- sliding
, for strictmfix
(liftM
h . f) =liftM
h (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.
Instances
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.
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-transforming monad.
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Examples
A common use of forever
is to process input from network sockets,
Handle
s, 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.
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 5
120
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)) 5
120
Instead of making a recursive call, we introduce a dummy parameter rec
;
when used within fix
, this parameter then refers to fix'
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.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
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.
Nothing
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 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:
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 |
:: 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.
Retrieves the monad environment.
:: (r -> r) | The function to modify the environment. |
-> m a |
|
-> m a |
Executes a computation in a modified environment.
:: (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.
ReaderT | |
|
Instances
Monad m => MonadReader r (ReaderT r m) | |
MonadError e m => MonadError e (ReaderT r m) | |
Defined in Control.Monad.Error.Class 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.
:: Reader r a | A |
-> r | An initial environment. |
-> a |
Runs a Reader
and extracts the final value from it.
(The inverse of reader
.)
:: (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
(withReader
f m) =runReader
m . f
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b #
Transform the computation inside a ReaderT
.
runReaderT
(mapReaderT
f m) = f .runReaderT
m
:: (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
(withReaderT
f m) =runReaderT
m . 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
ExitCode
as is in an attempt to exit with the requested code. - Wraps synchronous
PseudoException
in 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
:: (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.
ProgrammerError ProgrammerError | Mistakes programmers make |
ExternalError ExternalError | Errors thrown by the runtime |
Exit ExitCode | Process exit requests |
Instances
Show PseudoException | |
Defined in UnexceptionalIO showsPrec :: Int -> PseudoException -> ShowS # show :: PseudoException -> String # showList :: [PseudoException] -> ShowS # | |
Exception PseudoException | |
Defined in UnexceptionalIO |
data ProgrammerError #
Instances
Show ProgrammerError | |
Defined in UnexceptionalIO showsPrec :: Int -> ProgrammerError -> ShowS # show :: ProgrammerError -> String # showList :: [ProgrammerError] -> ShowS # | |
Exception ProgrammerError | |
Defined in UnexceptionalIO |
data ExternalError #
Pseudo-exceptions thrown by the runtime environment
Instances
Show ExternalError | |
Defined in UnexceptionalIO showsPrec :: Int -> ExternalError -> ShowS # show :: ExternalError -> String # showList :: [ExternalError] -> ShowS # | |
Exception ExternalError | |
Defined in UnexceptionalIO |
data SomeNonPseudoException #
Every SomeException
but PseudoException
Instances
Show SomeNonPseudoException | |
Defined in UnexceptionalIO showsPrec :: Int -> SomeNonPseudoException -> ShowS # show :: SomeNonPseudoException -> String # showList :: [SomeNonPseudoException] -> ShowS # | |
Exception SomeNonPseudoException | |
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
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
Instances
Show ChildThreadError | |
Defined in UnexceptionalIO showsPrec :: Int -> ChildThreadError -> ShowS # show :: ChildThreadError -> String # showList :: [ChildThreadError] -> ShowS # | |
Exception ChildThreadError | |
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 |
fromIO :: Unexceptional m => IO a -> ExceptT SomeNonPseudoException m a #
Catch any exception but PseudoException
in an IO
action