in-other-words-0.2.1.1: A higher-order effect system where the sky's the limit
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Internal.Intercept

Synopsis

Documentation

data Intercept (e :: Effect) :: Effect where Source #

An effect for intercepting actions of a first-order effect.

Even for this library, proper usage of this effect is very complicated. When properly used, this can be a very useful helper effect, allowing you write interpretations for a class of higher-order effects that wouldn't otherwise be possible.

For more information, see the wiki.

Constructors

Intercept :: Coercible z m => (forall x. e z x -> m x) -> m a -> Intercept e m a 

Instances

Instances details
(FirstOrder e, Eff (Unravel (InterceptB e)) m) => Handler InterceptH (Intercept e) m Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

data InterceptCont (e :: Effect) :: Effect where Source #

A variant of InterceptCont that is significantly more powerful, allowing you to capture the continuation of the program at each use-site of an effect, as well as aborting execution of the parameter computation early.

Constructors

InterceptCont :: Coercible z m => InterceptionMode -> (forall x. (x -> m a) -> e z x -> m a) -> m a -> InterceptCont e m a 

Instances

Instances details
(FirstOrder e, Member e (Derivs m), Eff (Unravel (InterceptB e)) m) => Handler InterceptH (InterceptCont e) m Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

data InterceptB e a where Source #

Constructors

InterceptB :: (forall q x. (x -> a) -> e q x -> a) -> InterceptB e a 

Instances

Instances details
(FirstOrder e, Carrier m, Threaders '[SteppedThreads] m p) => PrimHandler InterceptH (Unravel (InterceptB e)) (SteppedC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

interceptB :: forall e m q a. (FirstOrder e, Eff (Unravel (InterceptB e)) m) => (forall x. (x -> m a) -> e q x -> m a) -> m a -> m a Source #

newtype InterceptContC e m a Source #

Instances

Instances details
MonadBase b m => MonadBase b (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

liftBase :: b α -> InterceptContC e m α #

MonadTrans (InterceptContC e) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

lift :: Monad m => m a -> InterceptContC e m a #

Monad (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

(>>=) :: InterceptContC e m a -> (a -> InterceptContC e m b) -> InterceptContC e m b #

(>>) :: InterceptContC e m a -> InterceptContC e m b -> InterceptContC e m b #

return :: a -> InterceptContC e m a #

Functor (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

fmap :: (a -> b) -> InterceptContC e m a -> InterceptContC e m b #

(<$) :: a -> InterceptContC e m b -> InterceptContC e m a #

MonadFail m => MonadFail (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

fail :: String -> InterceptContC e m a #

Applicative (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

pure :: a -> InterceptContC e m a #

(<*>) :: InterceptContC e m (a -> b) -> InterceptContC e m a -> InterceptContC e m b #

liftA2 :: (a -> b -> c) -> InterceptContC e m a -> InterceptContC e m b -> InterceptContC e m c #

(*>) :: InterceptContC e m a -> InterceptContC e m b -> InterceptContC e m b #

(<*) :: InterceptContC e m a -> InterceptContC e m b -> InterceptContC e m a #

MonadIO m => MonadIO (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

liftIO :: IO a -> InterceptContC e m a #

MonadThrow m => MonadThrow (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

throwM :: Exception e0 => e0 -> InterceptContC e m a #

MonadCatch m => MonadCatch (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

catch :: Exception e0 => InterceptContC e m a -> (e0 -> InterceptContC e m a) -> InterceptContC e m a #

(FirstOrder e, Carrier m, Member e (Derivs m), Threaders '[SteppedThreads] m p) => Carrier (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Associated Types

type Derivs (InterceptContC e m) :: [Effect] Source #

type Prims (InterceptContC e m) :: [Effect] Source #

type Derivs (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

type Prims (InterceptContC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

runInterceptCont :: forall e m a p. (FirstOrder e, Carrier m, Member e (Derivs m), Threaders '[SteppedThreads] m p) => InterceptContC e m a -> m a Source #

Run Intercept e, InterceptCont e and e effects, provided that e is first-order and also part of the remaining effect stack.

There are three very important things to note here:

  • e must be first-order.
  • Any action of e made by a handler run after runInterceptCont won't get be intercepted. What this means is that you typically want to run the handler for e immediately after runInterceptCont.
  • This imposes the very restrictive primitive effect Unravel. Most notably, neither StateThreads nor WriterThreads accepts it. Because of that, this module offers various alternatives of several common State and Tell interpreters with threading constraints that do accept Unravel.
Derivs (InterceptContC e m) = InterceptCont e ': Intercept e ': e ': Derivs m
Prims  (InterceptContC e m) = Unravel (InterceptB e) ': Prims m

runStateStepped :: forall s m a p. (Carrier m, Threaders '[SteppedThreads] m p) => s -> SteppedC (State s) m a -> m (s, a) Source #

A variant of runState with a SteppedThreads threading constraint instead of a StateThreads threading constraint.

runTellListStepped :: forall o m a p. (Carrier m, Threaders '[SteppedThreads] m p) => SteppedC (Tell o) m a -> m ([o], a) Source #

A variant of runTell with a SteppedThreads threading constraint instead of a StateThreads threading constraint.

runTellStepped :: forall w m a p. (Monoid w, Carrier m, Threaders '[SteppedThreads] m p) => SteppedC (Tell w) m a -> m (w, a) Source #

A variant of runTell with a SteppedThreads threading constraint instead of a StateThreads threading constraint.

newtype ListenSteppedC w m a Source #

Instances

Instances details
MonadBase b m => MonadBase b (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

liftBase :: b α -> ListenSteppedC w m α #

MonadTrans (ListenSteppedC w) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

lift :: Monad m => m a -> ListenSteppedC w m a #

Monad (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

(>>=) :: ListenSteppedC w m a -> (a -> ListenSteppedC w m b) -> ListenSteppedC w m b #

(>>) :: ListenSteppedC w m a -> ListenSteppedC w m b -> ListenSteppedC w m b #

return :: a -> ListenSteppedC w m a #

Functor (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

fmap :: (a -> b) -> ListenSteppedC w m a -> ListenSteppedC w m b #

(<$) :: a -> ListenSteppedC w m b -> ListenSteppedC w m a #

MonadFail m => MonadFail (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

fail :: String -> ListenSteppedC w m a #

Applicative (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

pure :: a -> ListenSteppedC w m a #

(<*>) :: ListenSteppedC w m (a -> b) -> ListenSteppedC w m a -> ListenSteppedC w m b #

liftA2 :: (a -> b -> c) -> ListenSteppedC w m a -> ListenSteppedC w m b -> ListenSteppedC w m c #

(*>) :: ListenSteppedC w m a -> ListenSteppedC w m b -> ListenSteppedC w m b #

(<*) :: ListenSteppedC w m a -> ListenSteppedC w m b -> ListenSteppedC w m a #

MonadIO m => MonadIO (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

liftIO :: IO a -> ListenSteppedC w m a #

MonadThrow m => MonadThrow (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

throwM :: Exception e => e -> ListenSteppedC w m a #

MonadCatch m => MonadCatch (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

catch :: Exception e => ListenSteppedC w m a -> (e -> ListenSteppedC w m a) -> ListenSteppedC w m a #

(Monoid w, Carrier m, Threaders '[SteppedThreads] m p) => Carrier (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Associated Types

type Derivs (ListenSteppedC w m) :: [Effect] Source #

type Prims (ListenSteppedC w m) :: [Effect] Source #

type Derivs (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

type Prims (ListenSteppedC w m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

runListenStepped :: forall w m a p. (Monoid w, Carrier m, Threaders '[SteppedThreads] m p) => ListenSteppedC w m a -> m (w, a) Source #

A variant of runListen with a SteppedThreads threading constraint instead of a StateThreads threading constraint.

Derivs (ListenSteppedC w m) = Listen w ': Tell w ': Derivs m
Prims (ListenSteppedC w m) = ListenPrim w ': Derivs m

newtype ReifiedFOHandler e m Source #

Constructors

ReifiedFOHandler (forall q x. e q x -> m x) 

newtype InterceptRC (e :: Effect) m a Source #

Constructors

InterceptRC 

Instances

Instances details
MonadBase b m => MonadBase b (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

liftBase :: b α -> InterceptRC e m α #

MonadBaseControl b m => MonadBaseControl b (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Associated Types

type StM (InterceptRC e m) a #

Methods

liftBaseWith :: (RunInBase (InterceptRC e m) b -> b a) -> InterceptRC e m a #

restoreM :: StM (InterceptRC e m) a -> InterceptRC e m a #

MonadTrans (InterceptRC e) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

lift :: Monad m => m a -> InterceptRC e m a #

Monad m => Monad (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

(>>=) :: InterceptRC e m a -> (a -> InterceptRC e m b) -> InterceptRC e m b #

(>>) :: InterceptRC e m a -> InterceptRC e m b -> InterceptRC e m b #

return :: a -> InterceptRC e m a #

Functor m => Functor (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

fmap :: (a -> b) -> InterceptRC e m a -> InterceptRC e m b #

(<$) :: a -> InterceptRC e m b -> InterceptRC e m a #

MonadFix m => MonadFix (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

mfix :: (a -> InterceptRC e m a) -> InterceptRC e m a #

MonadFail m => MonadFail (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

fail :: String -> InterceptRC e m a #

Applicative m => Applicative (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

pure :: a -> InterceptRC e m a #

(<*>) :: InterceptRC e m (a -> b) -> InterceptRC e m a -> InterceptRC e m b #

liftA2 :: (a -> b -> c) -> InterceptRC e m a -> InterceptRC e m b -> InterceptRC e m c #

(*>) :: InterceptRC e m a -> InterceptRC e m b -> InterceptRC e m b #

(<*) :: InterceptRC e m a -> InterceptRC e m b -> InterceptRC e m a #

MonadIO m => MonadIO (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

liftIO :: IO a -> InterceptRC e m a #

Alternative m => Alternative (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

empty :: InterceptRC e m a #

(<|>) :: InterceptRC e m a -> InterceptRC e m a -> InterceptRC e m a #

some :: InterceptRC e m a -> InterceptRC e m [a] #

many :: InterceptRC e m a -> InterceptRC e m [a] #

MonadPlus m => MonadPlus (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

mzero :: InterceptRC e m a #

mplus :: InterceptRC e m a -> InterceptRC e m a -> InterceptRC e m a #

MonadThrow m => MonadThrow (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

throwM :: Exception e0 => e0 -> InterceptRC e m a #

MonadCatch m => MonadCatch (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

catch :: Exception e0 => InterceptRC e m a -> (e0 -> InterceptRC e m a) -> InterceptRC e m a #

MonadMask m => MonadMask (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Methods

mask :: ((forall a. InterceptRC e m a -> InterceptRC e m a) -> InterceptRC e m b) -> InterceptRC e m b #

uninterruptibleMask :: ((forall a. InterceptRC e m a -> InterceptRC e m a) -> InterceptRC e m b) -> InterceptRC e m b #

generalBracket :: InterceptRC e m a -> (a -> ExitCase b -> InterceptRC e m c) -> (a -> InterceptRC e m b) -> InterceptRC e m (b, c) #

(FirstOrder e, Carrier m, Threads (ReaderT (ReifiedFOHandler e m)) (Prims m)) => Carrier (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

Associated Types

type Derivs (InterceptRC e m) :: [Effect] Source #

type Prims (InterceptRC e m) :: [Effect] Source #

type Derivs (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

type Derivs (InterceptRC e m) = Intercept e ': (e ': Derivs m)
type Prims (InterceptRC e m) Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

type StM (InterceptRC e m) a Source # 
Instance details

Defined in Control.Effect.Internal.Intercept

type StM (InterceptRC e m) a = StM (ReaderT (ReifiedFOHandler e m) m) a

runInterceptR :: forall e m a p. (FirstOrder e, Member e (Derivs m), Carrier m, Threaders '[ReaderThreads] m p) => InterceptRC e m a -> m a Source #

Run Intercept e and e effects, provided e is first-order and part of the effect stack.

runInterceptR differs from runInterceptCont in four different ways:

There are some interpreters -- such as bracketToIO and concToIO -- that runInterceptCont can't be used together with in any capacity due to its SteppedThreads threading constraint. In these cases, runInterceptR can be used instead.

Derivs (InterceptRC e m) = Intercept e ': e ': 'Derivs m'
Prims  (InterceptRC e m) = Unlift (ReaderT (ReifiedFOHandler e m)) ': 'Derivs m'