{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
module FRP.Rhine.ClSF.Reader where
import Data.Tuple (swap)
import Control.Monad.Trans.Reader
import qualified Control.Monad.Trans.MSF.Reader as MSF
import FRP.Rhine.ClSF.Core
commuteReaders :: ReaderT r1 (ReaderT r2 m) a -> ReaderT r2 (ReaderT r1 m) a
commuteReaders a
= ReaderT $ \r1 -> ReaderT $ \r2 -> runReaderT (runReaderT a r2) r1
readerS
:: Monad m
=> ClSF m cl (a, r) b -> ClSF (ReaderT r m) cl a b
readerS behaviour
= liftMSFPurer commuteReaders $ MSF.readerS $ arr swap >>> behaviour
runReaderS
:: Monad m
=> ClSF (ReaderT r m) cl a b -> ClSF m cl (a, r) b
runReaderS behaviour
= arr swap >>> (MSF.runReaderS $ liftMSFPurer commuteReaders behaviour)
runReaderS_
:: Monad m
=> ClSF (ReaderT r m) cl a b -> r -> ClSF m cl a b
runReaderS_ behaviour r = arr (, r) >>> runReaderS behaviour