ether-0.4.0.2: Monad transformers and classes

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Trans.Ether.Dispatch

Contents

Description

Type-level machinery to manipulate constraints on the monad transformer stack.

Out of the box it provides the following dispatch strategies:

  • tagAttach to use functions defined using untagged monad classes as if they were defined using tagged ones.
  • tagReplace to use functions defined using one tag as if they were defined using another one.
import qualified Control.Monad.State as T
import Control.Ether.TH (ethereal)
import Control.Monad.Ether.State (MonadState)
import Control.Monad.Trans.Ether.Dispatch (tagAttach, tagDispatch)

ethereal "Foo" "foo"
ethereal "Bar" "bar"

f :: T.MonadState Int m => m String
f = fmap show T.get

g :: MonadState Foo Int m => m String
g = tagAttach foo f

h :: MonadState Bar Int m => m String
h = tagReplace foo bar g

Synopsis

The DispatchT monad transformer

data DispatchT dp m a Source

Wrap a monad to change its tags. Under the hood this is simply IdentityT, all the work is happening on the type level.

Dispatch types and functions

data K_TagAttach t Source

Encode type-level information for tagAttach.

Constructors

TagAttach t 

data K_TagReplace tOld tNew Source

Encode type-level information for tagReplace.

Constructors

TagReplace tOld tNew 

tagAttach :: proxy t -> DispatchTagAttachT t m a -> m a Source

Attach a tag to untagged transformers.

tagReplace :: proxy tOld -> proxy tNew -> DispatchTagReplaceT tOld tNew m a -> m a Source

Replace a tag with another tag.