module Network.Monad.Transfer where
import qualified Network.Stream as Stream
import Control.Monad.IO.Class (MonadIO(liftIO), )
import qualified Control.Monad.Exception.Asynchronous as Async
import qualified Control.Monad.Exception.Synchronous as Sync
import Control.Applicative (WrappedMonad(WrapMonad), unwrapMonad, )
import Data.Monoid (Monoid, )
type SyncExceptional m =
Sync.ExceptionalT Stream.ConnError m
type AsyncExceptional m =
Async.ExceptionalT Stream.ConnError m
data T m body =
Cons {
readLine :: AsyncExceptional m body,
readBlock :: Int -> AsyncExceptional m body,
writeBlock :: body -> SyncExceptional m ()
}
liftSync :: Monad m =>
m (Stream.Result a) -> SyncExceptional m a
liftSync = Sync.fromEitherT
liftAsync :: (Monad m, Monoid a) =>
m (Stream.Result a) -> AsyncExceptional m a
liftAsync =
Async.mapExceptionalT unwrapMonad .
Async.fromSynchronousMonoidT .
Sync.mapExceptionalT WrapMonad .
liftSync
liftIOSync :: MonadIO io =>
IO (Stream.Result a) -> SyncExceptional io a
liftIOSync = liftSync . liftIO
liftIOAsync :: (MonadIO io, Monoid a) =>
IO (Stream.Result a) -> AsyncExceptional io a
liftIOAsync = liftAsync . liftIO