fused-effects-0.4.0.0: A fast, flexible, fused effect system.

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Resumable

Synopsis

Documentation

data Resumable err (m :: * -> *) k Source #

Errors which can be resumed with values of some existentially-quantified type.

Constructors

Resumable (err a) (a -> k) 
Instances
Effect (Resumable err) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

handle :: Functor f => f () -> (forall x. f (m x) -> n (f x)) -> Resumable err m (m a) -> Resumable err n (n (f a)) Source #

HFunctor (Resumable err) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

fmap' :: (a -> b) -> Resumable err m a -> Resumable err m b Source #

hmap :: (forall x. m x -> n x) -> Resumable err m a -> Resumable err n a Source #

Functor (Resumable err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

fmap :: (a -> b) -> Resumable err m a -> Resumable err m b #

(<$) :: a -> Resumable err m b -> Resumable err m a #

Carrier sig m => Carrier (Resumable err :+: sig) (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

eff :: (Resumable err :+: sig) (ResumableWithC err m) (ResumableWithC err m a) -> ResumableWithC err m a Source #

(Carrier sig m, Effect sig) => Carrier (Resumable err :+: sig) (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

eff :: (Resumable err :+: sig) (ResumableC err m) (ResumableC err m a) -> ResumableC err m a Source #

throwResumable :: (Member (Resumable err) sig, Carrier sig m) => err a -> m a Source #

Throw an error which can be resumed with a value of its result type.

run (runResumable (throwResumable (Identity a))) == Left (SomeError (Identity a))

data SomeError (err :: * -> *) Source #

An error at some existentially-quantified type index.

Constructors

SomeError (err a) 
Instances
Eq1 err => Eq (SomeError err) Source #

Equality for SomeError is determined by an Eq1 instance for the error type.

Note that since we can’t tell whether the type indices are equal, let alone what Eq instance to use for them, the comparator passed to liftEq always returns True. Thus, SomeError is best used with type-indexed GADTs for the error type.

SomeError (Identity a) == SomeError (Identity b)
(SomeError (Const a) == SomeError (Const b)) == (a == b)
Instance details

Defined in Control.Effect.Resumable

Methods

(==) :: SomeError err -> SomeError err -> Bool #

(/=) :: SomeError err -> SomeError err -> Bool #

Ord1 err => Ord (SomeError err) Source #

Ordering for SomeError is determined by an Ord1 instance for the error type.

Note that since we can’t tell whether the type indices are equal, let alone what Ord instance to use for them, the comparator passed to liftCompare always returns EQ. Thus, SomeError is best used with type-indexed GADTs for the error type.

(SomeError (Identity a) `compare` SomeError (Identity b)) == EQ
(SomeError (Const a) `compare` SomeError (Const b)) == (a `compare` b)
Instance details

Defined in Control.Effect.Resumable

Methods

compare :: SomeError err -> SomeError err -> Ordering #

(<) :: SomeError err -> SomeError err -> Bool #

(<=) :: SomeError err -> SomeError err -> Bool #

(>) :: SomeError err -> SomeError err -> Bool #

(>=) :: SomeError err -> SomeError err -> Bool #

max :: SomeError err -> SomeError err -> SomeError err #

min :: SomeError err -> SomeError err -> SomeError err #

Show1 err => Show (SomeError err) Source #

Showing for SomeError is determined by a Show1 instance for the error type.

Note that since we can’t tell what Show instance to use for the type index, the functions passed to liftShowsPrec always return the empty ShowS. Thus, SomeError is best used with type-indexed GADTs for the error type.

show (SomeError (Identity a)) == "SomeError (Identity )"
show (SomeError (Const a)) == ("SomeError (Const " ++ showsPrec 11 a ")")
Instance details

Defined in Control.Effect.Resumable

Methods

showsPrec :: Int -> SomeError err -> ShowS #

show :: SomeError err -> String #

showList :: [SomeError err] -> ShowS #

NFData1 err => NFData (SomeError err) Source #

Evaluation of SomeError to normal forms is determined by a NFData1 instance for the error type.

pure (rnf (SomeError (Identity (error "error"))) :: SomeError Identity) `shouldThrow` errorCall "error"
Instance details

Defined in Control.Effect.Resumable

Methods

rnf :: SomeError err -> () #

runResumable :: ResumableC err m a -> m (Either (SomeError err) a) Source #

Run a Resumable effect, returning uncaught errors in Left and successful computations’ values in Right.

run (runResumable (pure a)) == Right @(SomeError Identity) @Int a

newtype ResumableC err m a Source #

Constructors

ResumableC 

Fields

Instances
MonadTrans (ResumableC err) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

lift :: Monad m => m a -> ResumableC err m a #

Monad m => Monad (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

(>>=) :: ResumableC err m a -> (a -> ResumableC err m b) -> ResumableC err m b #

(>>) :: ResumableC err m a -> ResumableC err m b -> ResumableC err m b #

return :: a -> ResumableC err m a #

fail :: String -> ResumableC err m a #

Functor m => Functor (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

fmap :: (a -> b) -> ResumableC err m a -> ResumableC err m b #

(<$) :: a -> ResumableC err m b -> ResumableC err m a #

MonadFail m => MonadFail (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

fail :: String -> ResumableC err m a #

Applicative m => Applicative (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

pure :: a -> ResumableC err m a #

(<*>) :: ResumableC err m (a -> b) -> ResumableC err m a -> ResumableC err m b #

liftA2 :: (a -> b -> c) -> ResumableC err m a -> ResumableC err m b -> ResumableC err m c #

(*>) :: ResumableC err m a -> ResumableC err m b -> ResumableC err m b #

(<*) :: ResumableC err m a -> ResumableC err m b -> ResumableC err m a #

MonadIO m => MonadIO (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

liftIO :: IO a -> ResumableC err m a #

Alternative m => Alternative (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

empty :: ResumableC err m a #

(<|>) :: ResumableC err m a -> ResumableC err m a -> ResumableC err m a #

some :: ResumableC err m a -> ResumableC err m [a] #

many :: ResumableC err m a -> ResumableC err m [a] #

(Alternative m, Monad m) => MonadPlus (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

mzero :: ResumableC err m a #

mplus :: ResumableC err m a -> ResumableC err m a -> ResumableC err m a #

(Carrier sig m, Effect sig) => Carrier (Resumable err :+: sig) (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

eff :: (Resumable err :+: sig) (ResumableC err m) (ResumableC err m a) -> ResumableC err m a Source #

runResumableWith :: (forall x. err x -> m x) -> ResumableWithC err m a -> m a Source #

Run a Resumable effect, resuming uncaught errors with a given handler.

Note that this may be less efficient than defining a specialized carrier type and instance specifying the handler’s behaviour directly. Performance-critical code may wish to do that to maximize the opportunities for fusion and inlining.

>>> data Err a where Err :: Int -> Err Int
run (runResumableWith (\ (Err b) -> pure (1 + b)) (pure a)) == a
run (runResumableWith (\ (Err b) -> pure (1 + b)) (throwResumable (Err a))) == 1 + a

newtype ResumableWithC err m a Source #

Constructors

ResumableWithC 

Fields

Instances
MonadTrans (ResumableWithC err) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

lift :: Monad m => m a -> ResumableWithC err m a #

Monad m => Monad (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

(>>=) :: ResumableWithC err m a -> (a -> ResumableWithC err m b) -> ResumableWithC err m b #

(>>) :: ResumableWithC err m a -> ResumableWithC err m b -> ResumableWithC err m b #

return :: a -> ResumableWithC err m a #

fail :: String -> ResumableWithC err m a #

Functor m => Functor (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

fmap :: (a -> b) -> ResumableWithC err m a -> ResumableWithC err m b #

(<$) :: a -> ResumableWithC err m b -> ResumableWithC err m a #

MonadFail m => MonadFail (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

fail :: String -> ResumableWithC err m a #

Applicative m => Applicative (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

pure :: a -> ResumableWithC err m a #

(<*>) :: ResumableWithC err m (a -> b) -> ResumableWithC err m a -> ResumableWithC err m b #

liftA2 :: (a -> b -> c) -> ResumableWithC err m a -> ResumableWithC err m b -> ResumableWithC err m c #

(*>) :: ResumableWithC err m a -> ResumableWithC err m b -> ResumableWithC err m b #

(<*) :: ResumableWithC err m a -> ResumableWithC err m b -> ResumableWithC err m a #

MonadIO m => MonadIO (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

liftIO :: IO a -> ResumableWithC err m a #

Alternative m => Alternative (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

empty :: ResumableWithC err m a #

(<|>) :: ResumableWithC err m a -> ResumableWithC err m a -> ResumableWithC err m a #

some :: ResumableWithC err m a -> ResumableWithC err m [a] #

many :: ResumableWithC err m a -> ResumableWithC err m [a] #

(Alternative m, Monad m) => MonadPlus (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

mzero :: ResumableWithC err m a #

mplus :: ResumableWithC err m a -> ResumableWithC err m a -> ResumableWithC err m a #

Carrier sig m => Carrier (Resumable err :+: sig) (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

eff :: (Resumable err :+: sig) (ResumableWithC err m) (ResumableWithC err m a) -> ResumableWithC err m a Source #