{- | Provide the explicit class dictionary as context via a Reader monad. -} module Network.Monad.Reader where import qualified Network.Monad.Transfer as Transfer import qualified Network.Stream as Stream import Control.Monad.Trans.Reader (ReaderT, asks, ) import Control.Monad.Trans (lift, ) import qualified Control.Monad.Exception.Asynchronous as Async import qualified Control.Monad.Exception.Synchronous as Sync type T body m = ReaderT (Transfer.T m body) m type SyncExceptional body m a = Sync.ExceptionalT Stream.ConnError (T body m) a type AsyncExceptional body m a = (T body m) (Async.Exceptional Stream.ConnError a) {-# INLINE readLine #-} readLine :: (Monad m) => AsyncExceptional body m body readLine = do action <- asks Transfer.readLine lift action {-# INLINE readBlock #-} readBlock :: (Monad m) => Int -> AsyncExceptional body m body readBlock n = do action <- asks Transfer.readBlock lift $ action n {-# INLINE writeBlock #-} writeBlock :: (Monad m) => body -> SyncExceptional body m () writeBlock body = do action <- lift $ asks Transfer.writeBlock Sync.mapExceptionalT lift $ action body