heftia-0.5.0.0: higher-order algebraic effects done right
Copyright(c) 2024 Sayo Koyoneda
LicenseMPL-2.0 (see the LICENSE file)
Maintainerymdfield@outlook.jp
Safe HaskellNone
LanguageGHC2021

Control.Monad.Hefty.Types

Description

This module defines the Eff monad and related fundamental types and functions. Please refer to the documentation of the top-level module.

Synopsis

Documentation

data Eff (eh :: [EffectH]) (ef :: [EffectF]) a Source #

The Eff monad represents computations with effects. It supports higher-order effects eh and first-order effects ef.

Constructors

Val a

A pure value.

Op

An effectful operation, which can be either a higher-order effect or a first-order effect.

Fields

Instances

Instances details
MemberBy key e ef => SendFOEBy (key :: k) e (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

sendFOEBy :: e a -> Eff eh ef a #

MemberHBy key e eh => SendHOEBy (key :: k) e (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

sendHOEBy :: e (Eff eh ef) a -> Eff eh ef a #

(SendFOEBy ReaderKey (Ask r) (Eff eh ef), SendHOEBy ReaderKey (Local r) (Eff eh ef), SendFOEBy WriterKey (Tell w) (Eff eh ef), SendHOEBy WriterKey (WriterH w) (Eff eh ef), SendFOEBy StateKey (State s) (Eff eh ef), Monoid w) => MonadRWS r w s (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

e <| ef => SendFOE e (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

sendFOE :: e a -> Eff eh ef a #

e <<| eh => SendHOE e (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

sendHOE :: e (Eff eh ef) a -> Eff eh ef a #

(SendFOEBy ErrorKey (Throw e) (Eff eh ef), SendHOEBy ErrorKey (Catch e) (Eff eh ef)) => MonadError e (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

throwError :: e -> Eff eh ef a #

catchError :: Eff eh ef a -> (e -> Eff eh ef a) -> Eff eh ef a #

(SendFOEBy ReaderKey (Ask r) (Eff eh ef), SendHOEBy ReaderKey (Local r) (Eff eh ef)) => MonadReader r (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

ask :: Eff eh ef r #

local :: (r -> r) -> Eff eh ef a -> Eff eh ef a #

reader :: (r -> a) -> Eff eh ef a #

SendFOEBy StateKey (State s) (Eff eh ef) => MonadState s (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

get :: Eff eh ef s #

put :: s -> Eff eh ef () #

state :: (s -> (a, s)) -> Eff eh ef a #

(SendFOEBy WriterKey (Tell w) (Eff eh ef), SendHOEBy WriterKey (WriterH w) (Eff eh ef), Monoid w) => MonadWriter w (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

writer :: (a, w) -> Eff eh ef a #

tell :: w -> Eff eh ef () #

listen :: Eff eh ef a -> Eff eh ef (a, w) #

pass :: Eff eh ef (a, w -> w) -> Eff eh ef a #

Fail <| ef => MonadFail (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

fail :: String -> Eff eh ef a #

Fix <<| eh => MonadFix (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

mfix :: (a -> Eff eh ef a) -> Eff eh ef a #

IO <| ef => MonadIO (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

liftIO :: IO a -> Eff eh ef a #

(Empty <| ef, ChooseH <<| eh) => Alternative (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

empty :: Eff eh ef a #

(<|>) :: Eff eh ef a -> Eff eh ef a -> Eff eh ef a #

some :: Eff eh ef a -> Eff eh ef [a] #

many :: Eff eh ef a -> Eff eh ef [a] #

Applicative (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

pure :: a -> Eff eh ef a #

(<*>) :: Eff eh ef (a -> b) -> Eff eh ef a -> Eff eh ef b #

liftA2 :: (a -> b -> c) -> Eff eh ef a -> Eff eh ef b -> Eff eh ef c #

(*>) :: Eff eh ef a -> Eff eh ef b -> Eff eh ef b #

(<*) :: Eff eh ef a -> Eff eh ef b -> Eff eh ef a #

Functor (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

fmap :: (a -> b) -> Eff eh ef a -> Eff eh ef b #

(<$) :: a -> Eff eh ef b -> Eff eh ef a #

Monad (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

(>>=) :: Eff eh ef a -> (a -> Eff eh ef b) -> Eff eh ef b #

(>>) :: Eff eh ef a -> Eff eh ef b -> Eff eh ef b #

return :: a -> Eff eh ef a #

(Empty <| ef, ChooseH <<| eh) => MonadPlus (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

mzero :: Eff eh ef a #

mplus :: Eff eh ef a -> Eff eh ef a -> Eff eh ef a #

(UnliftIO <<| eh, IO <| ef) => MonadUnliftIO (Eff eh ef) Source # 
Instance details

Defined in Control.Monad.Hefty.Types

Methods

withRunInIO :: ((forall a. Eff eh ef a -> IO a) -> IO b) -> Eff eh ef b #

type (:!!) = Eff infixr 4 Source #

Type-level infix operator for Eff. Allows writing eh :!! ef instead of Eff eh ef.

type (!!) (eh :: EffectH) (ef :: EffectF) = SumToRecUnionList UnionH eh :!! SumToRecUnionList Union ef infixr 5 Source #

An infix operator version of Eff for sum notation.

Example:

Span !! FileSystem + Time + Log + IO ~> IO

type ($) (f :: Type -> Type) a = f a infixr 3 Source #

Type-level infix applcation for functors.

type ($$) (h :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) = h f infixr 4 Source #

Type-level infix applcation for higher-order functors.

type Interpreter (e :: Type -> Type) (m :: Type -> Type) ans = forall x. e x -> (x -> m ans) -> m ans Source #

Type alias for an interpreter function.

Interpreter e m ans transforms an effect e into a computation in m where the result type (answer type) is ans.

type Elaborator (e :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) ans = Interpreter (e m) m ans Source #

Type alias for an elaborator function.

An Elaborator is an interpreter for higher-order effects.

type (~~>) (e :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) = e f ~> f infix 2 Source #

Type alias for a natural transformation style elaborator.

send :: forall (e :: EffectF) (ef :: [EffectF]) (eh :: [EffectH]). e <| ef => e ~> Eff eh ef Source #

Send a first-order effect e to the Eff carrier.

sendH :: forall (e :: EffectH) (eh :: [EffectH]) (ef :: [EffectF]). e <<| eh => e (Eff eh ef) ~> Eff eh ef Source #

Send a higher-order effect e to the Eff carrier.

send0 :: forall e (eh :: [EffectH]) (ef :: [Type -> Type]) x. e x -> Eff eh (e ': ef) x Source #

Send the first-order effect e at the head of the list to the Eff carrier.

send0H :: forall e (eh :: [(Type -> Type) -> Type -> Type]) (ef :: [EffectF]) x. e (Eff (e ': eh) ef) x -> Eff (e ': eh) ef x Source #

Send the higher-order effect e at the head of the list to the Eff carrier.

sendN :: forall (i :: Nat) (ef :: [Type -> Type]) (eh :: [EffectH]). KnownNat i => ElemAt i ef ~> Eff eh ef Source #

Send the i-th first-order effect in the list to the Eff carrier.

sendNH :: forall (i :: Nat) (eh :: [(Type -> Type) -> Type -> Type]) (ef :: [EffectF]). KnownNat i => ElemAt i eh (Eff eh ef) ~> Eff eh ef Source #

Send the i-th higher-order effect in the list to the Eff carrier.

sendUnion :: forall (ef :: [EffectF]) a (eh :: [EffectH]). Union ef a -> Eff eh ef a Source #

Send an open union of all first-order effects to the Eff carrier.

sendUnionBy :: forall a (eh :: [EffectH]) (ef :: [EffectF]) ans. (a -> Eff eh ef ans) -> Union ef a -> Eff eh ef ans Source #

Send an open union of all first-order effects, along with its continuation, to the Eff carrier.

sendUnionH :: forall (eh :: [EffectH]) (ef :: [EffectF]) a. UnionH eh (Eff eh ef) a -> Eff eh ef a Source #

Send an open union of all higher-order effects to the Eff carrier.

sendUnionHBy :: forall a (eh :: [EffectH]) (ef :: [EffectF]) ans. (a -> Eff eh ef ans) -> UnionH eh (Eff eh ef) a -> Eff eh ef ans Source #

Send an open union of all higher-order effects, along with its continuation, to the Eff carrier.

data ReaderKey Source #

A key to be attached to the effect targeted by the MonadReader instance.

Since MonadReader has a functional dependency on r, this is needed to uniquely specify r.

data WriterKey Source #

A key to be attached to the effect targeted by the MonadWriter instance.

Since MonadWriter has a functional dependency on w, this is needed to uniquely specify w.

data StateKey Source #

A key to be attached to the effect targeted by the MonadState instance.

Since MonadState has a functional dependency on s, this is needed to uniquely specify s.

data ErrorKey Source #

A key to be attached to the effect targeted by the MonadError instance.

Since MonadError has a functional dependency on e, this is needed to uniquely specify e.