interleavableIO-0.0.1: Use other Monads in functions that asks for an IO Monad.

Portabilityunportable
Stabilityunstable
MaintainerMarco Tlio Gontijo e Silva <marcot@riseup.net>

Control.Monad.Trans.InterleavableIO

Description

This module provides utilities to use functions that are not in the IO Monad as a callback in functions that expects an IO Monad.

Synopsis

Documentation

class MonadIO inner => InterleavableIO inner trans buffer | trans -> inner buffer whereSource

MonadIO types that instanciate this class can interleave an IO function, and be used as a callback in a function that asks for an IO monad.

Methods

embed :: (buffer -> inner result) -> trans resultSource

callback :: buffer -> trans result -> inner resultSource

Instances

InterleavableIO IO IO () 
(MonadIO inner, InterleavableIO deepInner inner buffer, InterleavableIO IO inner buffer, InterleavableIO IO deepInner buffer, Error error, Typeable error) => InterleavableIO deepInner (ErrorT error inner) ((), buffer) 
(MonadIO inner, InterleavableIO deepInner inner buffer, Monoid writer) => InterleavableIO deepInner (WriterT writer inner) (IORef writer, buffer) 
(MonadIO inner, InterleavableIO deepInner inner buffer) => InterleavableIO deepInner (ReaderT reader inner) (reader, buffer) 
(MonadIO inner, InterleavableIO deepInner inner buffer) => InterleavableIO deepInner (StateT state inner) (IORef state, buffer) 

embedCallbackSource

Arguments

:: (InterleavableIO innerCaller caller buffer, InterleavableIO innerFunction function buffer) 
=> (innerFunction resultFunction -> innerCaller resultCaller)
caller
-> function resultFunction
callback
-> caller resultCaller 

This is an utilitary function to the most simple use-case of this module. It makes it possible to use the function caller, that needs an IO as input, with any Monad that instanciates InterleavableIO.

embedInnerSource

Arguments

:: InterleavableIO inner trans innerBuffer 
=> ((buffer, innerBuffer) -> inner result)

readBuffer: Usually the first parameter of embed.

-> buffer

buffer: What should be the first parameter of readBuffer in cases without nested Monads.

-> trans result 

This is a utilitary function to construct new instances of InterleavableIO, in Monads that contain InterleavableIO Monads. It simply calls embed with an inner buffer that will be used by the inner instance of InterleavableIO.

promoteState :: MonadState state monad => State state result -> monad resultSource

Function useful to convert a pure State monad in a StateT IO, to be used with the instance of InterleavableIO StateT.

promoteReader :: MonadReader reader monad => Reader reader result -> monad resultSource

Function useful to convert a pure Reader monad in a ReaderT IO, to be used with the instance of InterleavableIO ReaderT.

promoteWriter :: MonadWriter writer monad => Writer writer result -> monad resultSource

Function useful to convert a pure Writer monad in a WriterT IO, to be used with the instance of InterleavableIO WriterT.

data InterleaveErrorTException error Source

Error data type used in ErrorT instance.

Constructors

InterleaveErrorTException error