fused-effects-0.2.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, Monad m) => Carrier (Resumable err :+: sig) (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

ret :: a -> ResumableWithC err m a Source #

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

ret :: a -> ResumableC err m a Source #

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 :: (Carrier sig m, Effect sig) => Eff (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
(Carrier sig m, Effect sig) => Carrier (Resumable err :+: sig) (ResumableC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

ret :: a -> ResumableC err m a Source #

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

runResumableWith :: (Carrier sig m, Monad m) => (forall x. err x -> m x) -> Eff (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 ((forall x. err x -> m x) -> m a) 
Instances
(Carrier sig m, Monad m) => Carrier (Resumable err :+: sig) (ResumableWithC err m) Source # 
Instance details

Defined in Control.Effect.Resumable

Methods

ret :: a -> ResumableWithC err m a Source #

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