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

Control.Effect.Regional

Synopsis

Effects

data Regional s :: Effect where Source #

A helper primitive effect for manipulating a region.

Helper primitive effects are effects that allow you to avoid interpreting one of your own effects as a primitive if the power needed from direct access to the underlying monad can instead be provided by the relevant helper primitive effect. The reason why you'd want to do this is that helper primitive effects already have ThreadsEff instances defined for them; so you don't have to define any for your own effect.

The helper primitive effects offered in this library are -- in order of ascending power -- Regional, Optional, BaseControl and Unlift.

The typical use-case of Regional is to lift a natural transformation of a base monad. Hoist and accompaning interpreters is provided as a specialization of Regional for this purpose.

Regional in its most general form lacks a pre-defined interpreter: when not using Hoist, you're expected to define your own interpreter for Regional (treating it as a primitive effect).

Regional is typically used as a primitive effect. If you define a Carrier that relies on a novel non-trivial monad transformer t, then you need to make a a ThreadsEff t (Regional s) instance (if possible). threadRegionalViaOptional can help you with that.

The following threading constraints accept Regional:

Constructors

Regionally :: s -> m a -> Regional s m a 

Instances

Instances details
ThreadsEff ListT (Regional s) Source # 
Instance details

Defined in Control.Monad.Trans.List.Church

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (ListT m) a -> ListT m a Source #

(Carrier m, MonadBaseControl b m) => PrimHandler HoistToFinalH (Hoist b) m Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Carrier m => PrimHandler HoistH (Hoist m) m Source # 
Instance details

Defined in Control.Effect.Internal.Regional

ThreadsEff (ExceptT e) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (ExceptT e m) a -> ExceptT e m a Source #

ThreadsEff (WriterT w) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (WriterT w m) a -> WriterT w m a Source #

ThreadsEff (StateT i) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (StateT i m) a -> StateT i m a Source #

ThreadsEff (ReaderT i) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (ReaderT i m) a -> ReaderT i m a Source #

ThreadsEff (StateT i) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (StateT i m) a -> StateT i m a Source #

ThreadsEff (WriterT w) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (WriterT w m) a -> WriterT w m a Source #

Monoid w => ThreadsEff (WriterT w) (Regional s) Source # 
Instance details

Defined in Control.Effect.Type.Regional

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (WriterT w m) a -> WriterT w m a Source #

ThreadsEff (FreeT f) (Regional s) Source # 
Instance details

Defined in Control.Monad.Trans.Free.Church.Alternate

Methods

threadEff :: Monad m => (forall x. Regional s m x -> m x) -> Regional s (FreeT f m) a -> FreeT f m a Source #

type Hoist (b :: * -> *) = Regional (HoistCall b) Source #

A useful specialization of Regional where the constant type is HoistCall b. From this, you can derive hoist.

Actions

regionally :: Eff (Regional s) m => s -> m a -> m a Source #

Execute a computation modified in some way, providing the interpreter of Regional s a constant to indicate how the computation should be modified.

hoist :: Eff (Hoist b) m => (forall x. b x -> b x) -> m a -> m a Source #

Lift a natural transformation of a base monad to the current monad.

Interpretations

runHoist :: Carrier m => HoistC m a -> m a Source #

Run a Hoist m effect, where the base monad m is the current monad.

Derivs (HoistC m) = Hoist m ': Derivs m
Prims  (HoistC m) = Hoist m ': Prims m

hoistToFinal :: (MonadBaseControl b m, Carrier m) => HoistToFinalC b m a -> m a Source #

Run a Hoist b effect, where the base monad b is the final base monad.

Derivs (HoistToFinalC b m) = Hoist b ': Derivs m
Prims  (HoistToFinalC b m) = Hoist b ': Prims m

Threading utilities

threadRegionalViaOptional :: (ThreadsEff t (Optional (Const s)), Monad m) => (forall x. Regional s m x -> m x) -> Regional s (t m) a -> t m a Source #

A valid definition of threadEff for a ThreadsEff (Regional s) t instance, given that t threads Optional f for any functor f.

Combinators for Algebras

powerAlgHoist :: forall m p a. Algebra' p m a -> Algebra' (Hoist m ': p) m a Source #

Strengthen an Algebra p m by adding a Hoist m handler

powerAlgHoistFinal :: forall b m p a. MonadBaseControl b m => Algebra' p m a -> Algebra' (Hoist b ': p) m a Source #

Strengthen an Algebra p m by adding a Hoist b handler, where b is the final base monad.

Carriers

data HoistC m a Source #

Instances

Instances details
MonadTrans (HoistC :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

lift :: Monad m => m a -> HoistC m a #

MonadTransControl (HoistC :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Associated Types

type StT HoistC a #

Methods

liftWith :: Monad m => (Run HoistC -> m a) -> HoistC m a #

restoreT :: Monad m => m (StT HoistC a) -> HoistC m a #

Monad m => Monad (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

(>>=) :: HoistC m a -> (a -> HoistC m b) -> HoistC m b #

(>>) :: HoistC m a -> HoistC m b -> HoistC m b #

return :: a -> HoistC m a #

Functor m => Functor (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

fmap :: (a -> b) -> HoistC m a -> HoistC m b #

(<$) :: a -> HoistC m b -> HoistC m a #

MonadFix m => MonadFix (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

mfix :: (a -> HoistC m a) -> HoistC m a #

MonadFail m => MonadFail (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

fail :: String -> HoistC m a #

Applicative m => Applicative (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

pure :: a -> HoistC m a #

(<*>) :: HoistC m (a -> b) -> HoistC m a -> HoistC m b #

liftA2 :: (a -> b -> c) -> HoistC m a -> HoistC m b -> HoistC m c #

(*>) :: HoistC m a -> HoistC m b -> HoistC m b #

(<*) :: HoistC m a -> HoistC m b -> HoistC m a #

MonadIO m => MonadIO (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

liftIO :: IO a -> HoistC m a #

Alternative m => Alternative (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

empty :: HoistC m a #

(<|>) :: HoistC m a -> HoistC m a -> HoistC m a #

some :: HoistC m a -> HoistC m [a] #

many :: HoistC m a -> HoistC m [a] #

MonadPlus m => MonadPlus (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

mzero :: HoistC m a #

mplus :: HoistC m a -> HoistC m a -> HoistC m a #

MonadThrow m => MonadThrow (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

throwM :: Exception e => e -> HoistC m a #

MonadCatch m => MonadCatch (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

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

MonadMask m => MonadMask (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Methods

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

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

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

Carrier m => Carrier (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

Associated Types

type Derivs (HoistC m) :: [Effect] Source #

type Prims (HoistC m) :: [Effect] Source #

type StT (HoistC :: (Type -> Type) -> Type -> Type) a Source # 
Instance details

Defined in Control.Effect.Internal.Regional

type StT (HoistC :: (Type -> Type) -> Type -> Type) a = StT (IdentityT :: (Type -> Type) -> Type -> Type) a
type Derivs (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional

type Prims (HoistC m) Source # 
Instance details

Defined in Control.Effect.Internal.Regional