effet-0.4.0.0: An Effect System based on Type Classes
Copyright(c) Michael Szvetits 2020
LicenseBSD3 (see the file LICENSE)
Maintainertypedbyte@qualified.name
Stabilitystable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Machinery.Via

Description

This module defines the types EachVia and its corresponding type synonym Via which indicate that specific effects are handled by a specific monad transformer (also known as effect handler or effect interpreter).

It also defines the G type, which is the global tag that is used for untagged effects.

Last but not least, it defines some constraint synonyms and kinds that are used throughout this library, hopefully to increase the readability of the code at some points.

Synopsis

Core Types

newtype EachVia (effs :: [Effect]) (t :: Transformer) m a Source #

This type indicates that the effects (i.e., type classes) effs are handled by a specific monad transformer t. The type is a simple wrapper around the monad transformer itself. The whole purpose of this type is to guide the type system to pick the instances of type classes effs given by the type t, and to delegate all other effects that are not in effs to their handlers which are located somewhere further down the monad transformer stack.

Since: 0.2.0.0

Constructors

EachVia 

Fields

Instances

Instances details
Handle '[Reader' tag r, Writer' tag w, State' tag s] (RWS' tag r w s) others t m => RWS' (tag :: k) r w s (EachVia (RWS' tag r w s ': others) t m) Source # 
Instance details

Defined in Control.Effect.RWS

Find '[Reader' tag r, Writer' tag w, State' tag s] (RWS' tag r w s) other effs t m => RWS' (tag :: k) r w s (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.RWS

Lift '[Reader' tag r, Writer' tag w, State' tag s] (RWS' tag r w s) t m => RWS' (tag :: k) r w s (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.RWS

Handle '[Monad] (Map' tag k2 v) others t m => Map' (tag :: k1) k2 v (EachVia (Map' tag k2 v ': others) t m) Source # 
Instance details

Defined in Control.Effect.Map

Methods

clear' :: EachVia (Map' tag k2 v ': others) t m () Source #

lookup' :: k2 -> EachVia (Map' tag k2 v ': others) t m (Maybe v) Source #

update' :: k2 -> Maybe v -> EachVia (Map' tag k2 v ': others) t m () Source #

Find '[Monad] (Map' tag k2 v) other effs t m => Map' (tag :: k1) k2 v (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Map

Methods

clear' :: EachVia (other ': effs) t m () Source #

lookup' :: k2 -> EachVia (other ': effs) t m (Maybe v) Source #

update' :: k2 -> Maybe v -> EachVia (other ': effs) t m () Source #

Lift '[Monad] (Map' tag k2 v) t m => Map' (tag :: k1) k2 v (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Map

Methods

clear' :: EachVia '[] t m () Source #

lookup' :: k2 -> EachVia '[] t m (Maybe v) Source #

update' :: k2 -> Maybe v -> EachVia '[] t m () Source #

Handle '[Monad] (Error' tag e) others t m => Error' (tag :: k) e (EachVia (Error' tag e ': others) t m) Source # 
Instance details

Defined in Control.Effect.Error

Methods

throwError' :: e -> EachVia (Error' tag e ': others) t m a Source #

catchError' :: EachVia (Error' tag e ': others) t m a -> (e -> EachVia (Error' tag e ': others) t m a) -> EachVia (Error' tag e ': others) t m a Source #

Find '[Monad] (Error' tag e) other effs t m => Error' (tag :: k) e (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Error

Methods

throwError' :: e -> EachVia (other ': effs) t m a Source #

catchError' :: EachVia (other ': effs) t m a -> (e -> EachVia (other ': effs) t m a) -> EachVia (other ': effs) t m a Source #

Control '[Monad] (Error' tag e) t m => Error' (tag :: k) e (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Error

Methods

throwError' :: e -> EachVia '[] t m a Source #

catchError' :: EachVia '[] t m a -> (e -> EachVia '[] t m a) -> EachVia '[] t m a Source #

Handle '[Monad] (Embed' tag n) others t m => Embed' (tag :: k) n (EachVia (Embed' tag n ': others) t m) Source # 
Instance details

Defined in Control.Effect.Embed

Methods

embed' :: n a -> EachVia (Embed' tag n ': others) t m a Source #

Find '[Monad] (Embed' tag n) other effs t m => Embed' (tag :: k) n (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Embed

Methods

embed' :: n a -> EachVia (other ': effs) t m a Source #

Lift '[Monad] (Embed' tag n) t m => Embed' (tag :: k) n (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Embed

Methods

embed' :: n a -> EachVia '[] t m a Source #

Handle '[Monad] (Reader' tag r) others t m => Reader' (tag :: k) r (EachVia (Reader' tag r ': others) t m) Source # 
Instance details

Defined in Control.Effect.Reader

Methods

ask' :: EachVia (Reader' tag r ': others) t m r Source #

local' :: (r -> r) -> EachVia (Reader' tag r ': others) t m a -> EachVia (Reader' tag r ': others) t m a Source #

reader' :: (r -> a) -> EachVia (Reader' tag r ': others) t m a Source #

Find '[Monad] (Reader' tag r) other effs t m => Reader' (tag :: k) r (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Reader

Methods

ask' :: EachVia (other ': effs) t m r Source #

local' :: (r -> r) -> EachVia (other ': effs) t m a -> EachVia (other ': effs) t m a Source #

reader' :: (r -> a) -> EachVia (other ': effs) t m a Source #

Control '[Monad] (Reader' tag r) t m => Reader' (tag :: k) r (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Reader

Methods

ask' :: EachVia '[] t m r Source #

local' :: (r -> r) -> EachVia '[] t m a -> EachVia '[] t m a Source #

reader' :: (r -> a) -> EachVia '[] t m a Source #

Handle '[Monad] (State' tag s) others t m => State' (tag :: k) s (EachVia (State' tag s ': others) t m) Source # 
Instance details

Defined in Control.Effect.State

Methods

get' :: EachVia (State' tag s ': others) t m s Source #

put' :: s -> EachVia (State' tag s ': others) t m () Source #

state' :: (s -> (s, a)) -> EachVia (State' tag s ': others) t m a Source #

Find '[Monad] (State' tag s) other effs t m => State' (tag :: k) s (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.State

Methods

get' :: EachVia (other ': effs) t m s Source #

put' :: s -> EachVia (other ': effs) t m () Source #

state' :: (s -> (s, a)) -> EachVia (other ': effs) t m a Source #

Lift '[Monad] (State' tag s) t m => State' (tag :: k) s (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.State

Methods

get' :: EachVia '[] t m s Source #

put' :: s -> EachVia '[] t m () Source #

state' :: (s -> (s, a)) -> EachVia '[] t m a Source #

Handle '[Monad] (Writer' tag w) others t m => Writer' (tag :: k) w (EachVia (Writer' tag w ': others) t m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

tell' :: w -> EachVia (Writer' tag w ': others) t m () Source #

listen' :: EachVia (Writer' tag w ': others) t m a -> EachVia (Writer' tag w ': others) t m (w, a) Source #

censor' :: (w -> w) -> EachVia (Writer' tag w ': others) t m a -> EachVia (Writer' tag w ': others) t m a Source #

Find '[Monad] (Writer' tag w) other effs t m => Writer' (tag :: k) w (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

tell' :: w -> EachVia (other ': effs) t m () Source #

listen' :: EachVia (other ': effs) t m a -> EachVia (other ': effs) t m (w, a) Source #

censor' :: (w -> w) -> EachVia (other ': effs) t m a -> EachVia (other ': effs) t m a Source #

Control '[Monad] (Writer' tag w) t m => Writer' (tag :: k) w (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

tell' :: w -> EachVia '[] t m () Source #

listen' :: EachVia '[] t m a -> EachVia '[] t m (w, a) Source #

censor' :: (w -> w) -> EachVia '[] t m a -> EachVia '[] t m a Source #

Handle '[Monad] (Cont' tag) others t m => Cont' (tag :: k) (EachVia (Cont' tag ': others) t m) Source # 
Instance details

Defined in Control.Effect.Cont

Methods

callCC' :: ((a -> EachVia (Cont' tag ': others) t m b) -> EachVia (Cont' tag ': others) t m a) -> EachVia (Cont' tag ': others) t m a Source #

Find '[Monad] (Cont' tag) other effs t m => Cont' (tag :: k) (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Cont

Methods

callCC' :: ((a -> EachVia (other ': effs) t m b) -> EachVia (other ': effs) t m a) -> EachVia (other ': effs) t m a Source #

Control ('[] :: [Effect]) (Cont' tag) t m => Cont' (tag :: k) (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Cont

Methods

callCC' :: ((a -> EachVia '[] t m b) -> EachVia '[] t m a) -> EachVia '[] t m a Source #

Handle '[MonadIO] (Managed' tag) others t m => Managed' (tag :: k) (EachVia (Managed' tag ': others) t m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: EachVia (Managed' tag ': others) t m a -> (a -> EachVia (Managed' tag ': others) t m b) -> EachVia (Managed' tag ': others) t m a Source #

Find '[MonadIO] (Managed' tag) other effs t m => Managed' (tag :: k) (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: EachVia (other ': effs) t m a -> (a -> EachVia (other ': effs) t m b) -> EachVia (other ': effs) t m a Source #

Control '[MonadIO] (Managed' tag) t m => Managed' (tag :: k) (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: EachVia '[] t m a -> (a -> EachVia '[] t m b) -> EachVia '[] t m a Source #

Handle '[MonadIO] (Resource' tag) others t m => Resource' (tag :: k) (EachVia (Resource' tag ': others) t m) Source # 
Instance details

Defined in Control.Effect.Resource

Methods

bracket' :: EachVia (Resource' tag ': others) t m a -> (a -> EachVia (Resource' tag ': others) t m c) -> (a -> EachVia (Resource' tag ': others) t m b) -> EachVia (Resource' tag ': others) t m b Source #

bracketOnError' :: EachVia (Resource' tag ': others) t m a -> (a -> EachVia (Resource' tag ': others) t m c) -> (a -> EachVia (Resource' tag ': others) t m b) -> EachVia (Resource' tag ': others) t m b Source #

Find '[MonadIO] (Resource' tag) other effs t m => Resource' (tag :: k) (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Resource

Methods

bracket' :: EachVia (other ': effs) t m a -> (a -> EachVia (other ': effs) t m c) -> (a -> EachVia (other ': effs) t m b) -> EachVia (other ': effs) t m b Source #

bracketOnError' :: EachVia (other ': effs) t m a -> (a -> EachVia (other ': effs) t m c) -> (a -> EachVia (other ': effs) t m b) -> EachVia (other ': effs) t m b Source #

Control '[MonadIO] (Resource' tag) t m => Resource' (tag :: k) (EachVia ('[] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Resource

Methods

bracket' :: EachVia '[] t m a -> (a -> EachVia '[] t m c) -> (a -> EachVia '[] t m b) -> EachVia '[] t m b Source #

bracketOnError' :: EachVia '[] t m a -> (a -> EachVia '[] t m c) -> (a -> EachVia '[] t m b) -> EachVia '[] t m b Source #

(Monad (t m), MonadBase b m, MonadTrans t) => MonadBase b (EachVia effs t m) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Methods

liftBase :: b α -> EachVia effs t m α #

(Monad (t m), MonadBaseControl b m, MonadTransControl t) => MonadBaseControl b (EachVia effs t m) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Associated Types

type StM (EachVia effs t m) a #

Methods

liftBaseWith :: (RunInBase (EachVia effs t m) b -> b a) -> EachVia effs t m a #

restoreM :: StM (EachVia effs t m) a -> EachVia effs t m a #

MonadTrans t => MonadTrans (EachVia effs t) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Methods

lift :: Monad m => m a -> EachVia effs t m a #

MonadTransControl t => MonadTransControl (EachVia effs t) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Associated Types

type StT (EachVia effs t) a #

Methods

liftWith :: Monad m => (Run (EachVia effs t) -> m a) -> EachVia effs t m a #

restoreT :: Monad m => m (StT (EachVia effs t) a) -> EachVia effs t m a #

Monad (t m) => Monad (EachVia effs t m) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Methods

(>>=) :: EachVia effs t m a -> (a -> EachVia effs t m b) -> EachVia effs t m b #

(>>) :: EachVia effs t m a -> EachVia effs t m b -> EachVia effs t m b #

return :: a -> EachVia effs t m a #

Functor (t m) => Functor (EachVia effs t m) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Methods

fmap :: (a -> b) -> EachVia effs t m a -> EachVia effs t m b #

(<$) :: a -> EachVia effs t m b -> EachVia effs t m a #

Applicative (t m) => Applicative (EachVia effs t m) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Methods

pure :: a -> EachVia effs t m a #

(<*>) :: EachVia effs t m (a -> b) -> EachVia effs t m a -> EachVia effs t m b #

liftA2 :: (a -> b -> c) -> EachVia effs t m a -> EachVia effs t m b -> EachVia effs t m c #

(*>) :: EachVia effs t m a -> EachVia effs t m b -> EachVia effs t m b #

(<*) :: EachVia effs t m a -> EachVia effs t m b -> EachVia effs t m a #

MonadIO (t m) => MonadIO (EachVia effs t m) Source # 
Instance details

Defined in Control.Effect.Machinery.Via

Methods

liftIO :: IO a -> EachVia effs t m a #

type StT (EachVia effs t) a Source # 
Instance details

Defined in Control.Effect.Machinery.Via

type StT (EachVia effs t) a = StT t a
type StM (EachVia effs t m) a Source # 
Instance details

Defined in Control.Effect.Machinery.Via

type StM (EachVia effs t m) a = ComposeSt t m a

type Via eff t m a = EachVia '[eff] t m a Source #

This type synonym can be used to indicate that a single effect eff is handled by a specific monad transformer t.

Since: 0.2.0.0

data G Source #

This type is used as tag for all untagged effects. In order words, every effect is tagged, even untagged ones, but all the untagged ones simply have the same tag G (short for "Global", because you can view tags as some kind of namespace mechanism, and all untagged effects live in the same global namespace).

If you don't want to use tagged effects (i.e., you write effect type classes without a tag type parameter), you can ignore this type completely.

Constraint Synonyms and Kinds

type SomeMonad = Type -> Type Source #

The kind of monads.

type Effect = SomeMonad -> Constraint Source #

The kind of effects, which are type classes with a monad type parameter at the end.

type Transformer = SomeMonad -> Type -> Type Source #

The kind of monad transformers, also known as effect handlers or effect interpreters.

type Handle (cxt :: [Effect]) (eff :: Effect) (others :: [Effect]) (t :: Transformer) m = (eff (t m), Expand cxt (eff ': others) t m) Source #

This constraint synonym indicates that an effect is handled by a specific monad transformer.

Since: 0.4.0.0

type Find (cxt :: [Effect]) (eff :: Effect) (other :: Effect) (effs :: [Effect]) (t :: Transformer) m = (eff (EachVia effs t m), Expand cxt (other ': effs) t m) Source #

This constraint synonym indicates that an effect eff is not at the head of the type level list of effects to be handled, so the effect must be found further down in the tail effs.

Since: 0.4.0.0

type Lift (cxt :: [Effect]) (eff :: Effect) (t :: Transformer) m = (eff m, Expand cxt '[] t m, MonadTrans t) Source #

This constraint synonym indicates that a first-order effect is not handled by a specific monad transformer and must thus be delegated ("lifted") further down the monad transformer stack in order to find its associated handler.

Roughly speaking, a first-order effect is a type class whose monad type parameter m appears only in positive position when looking at the types of its corresponding class methods (e.g., m appears only in the result type).

An example of a first-order effect is the State' effect.

Since: 0.4.0.0

type Control (cxt :: [Effect]) (eff :: Effect) (t :: Transformer) m = (eff m, Expand cxt '[] t m, Monad (t m), MonadTransControl t) Source #

This constraint synonym indicates that a higher-order effect is not handled by a specific monad transformer and must thus be delegated ("lifted") further down the monad transformer stack in order to find its associated handler.

Roughly speaking, a higher-order effect is a type class whose monad type parameter m appears in negative position when looking at the types of its corresponding class methods (e.g., m appears in the type of a method parameter).

An example of a higher-order effect is the Reader' effect, since its class method local' has a parameter of type m a.

Since: 0.4.0.0

Convenience Functions

type family Expand (cxt :: [Effect]) (effs :: [Effect]) (t :: Transformer) m :: Constraint where ... Source #

Type-level helper function to apply a list of constraints (i.e., effects) to EachVia. One should not call this by hand, it will be used by the generated code or called by Handle, Find, Lift and Control.

Since: 0.4.0.0

Equations

Expand '[] effs t m = () 
Expand (cxt ': cxts) effs t m = (cxt (EachVia effs t m), Expand cxts effs t m)