{-# LANGUAGE FlexibleInstances, FunctionalDependencies, TypeFamilies, Rank2Types, UndecidableInstances #-}
module Control.Monad.Trans.Control.Identity (
MonadTransControlIdentity (..)
, defaultLiftWithIdentity
, MonadBaseControlIdentity (..)
, defaultLiftBaseWithIdentity
) where
import Control.Monad.Trans.Control
import Control.Monad.Trans.Identity
import Control.Monad.Trans.Reader
class MonadTransControl t => MonadTransControlIdentity t where
liftWithIdentity :: Monad m => ((forall x. t m x -> m x) -> m a) -> t m a
defaultLiftWithIdentity :: (Monad m, MonadTransControl t)
=> ((forall x. StT t x ~ x => t m x -> m x) -> m a)
-> t m a
defaultLiftWithIdentity = liftWith
instance MonadTransControlIdentity IdentityT where
liftWithIdentity = defaultLiftWithIdentity
instance MonadTransControlIdentity (ReaderT r) where
liftWithIdentity = defaultLiftWithIdentity
class MonadBaseControl b m => MonadBaseControlIdentity b m | m -> b where
liftBaseWithIdentity :: ((forall x. m x -> b x) -> b a) -> m a
defaultLiftBaseWithIdentity :: (MonadBaseControlIdentity b m, MonadTransControlIdentity t)
=> ((forall x. t m x -> b x) -> b a)
-> t m a
defaultLiftBaseWithIdentity inner = liftWithIdentity $ \ runId ->
liftBaseWithIdentity $ \ runIdInBase ->
inner $ runIdInBase . runId
instance MonadBaseControl b b => MonadBaseControlIdentity b b where
liftBaseWithIdentity inner = inner id
instance MonadBaseControlIdentity b m => MonadBaseControlIdentity b (IdentityT m) where
liftBaseWithIdentity = defaultLiftBaseWithIdentity
instance MonadBaseControlIdentity b m => MonadBaseControlIdentity b (ReaderT r m) where
liftBaseWithIdentity = defaultLiftBaseWithIdentity