module Control.Monad.Resumable.Scoped where
import Control.Monad.Resumable
import Control.Monad.Cont (ContT)
import Control.Monad.Error (ErrorT)
import Control.Monad.List (ListT)
import Control.Monad.RWS (RWST)
import Control.Monad.Reader (ReaderT)
import Control.Monad.State (StateT)
import Control.Monad.Writer (WriterT)
import Unsafe.Coerce
data Static = Static
data Dynamic = Dynamic
asStatic :: ResumableT Static req res m a -> ResumableT Static req res m a
asStatic = id
asDynamic :: ResumableT Dynamic req res m a -> ResumableT Dynamic req res m a
asDynamic = id
statically :: Scoped Static m =>
(ScopedAs Static m a -> ScopedAs Static m b) -> m a -> m b
statically = scoped Static
dynamically :: Scoped Dynamic m =>
(ScopedAs Dynamic m a -> ScopedAs Dynamic m b) -> m a -> m b
dynamically = scoped Dynamic
class Scoped scope m where
type ScopedAs scope m :: * -> *
scoped :: scope -> (ScopedAs scope m a -> ScopedAs scope m b) -> m a -> m b
scoped _ f = unsafeCoerce . f . unsafeCoerce
instance Scoped scope (ResumableT scope' req res m) where
type ScopedAs scope (ResumableT scope' req res m) = ResumableT scope req res m
instance Scoped scope m => Scoped scope (ContT r m) where
type ScopedAs scope (ContT r m) = ContT r (ScopedAs scope m)
instance Scoped scope m => Scoped scope (ErrorT e m) where
type ScopedAs scope (ErrorT e m) = ErrorT e (ScopedAs scope m)
instance Scoped scope m => Scoped scope (ListT m) where
type ScopedAs scope (ListT m) = ListT (ScopedAs scope m)
instance Scoped scope m => Scoped scope (RWST r w s m) where
type ScopedAs scope (RWST r w s m) = RWST r w s (ScopedAs scope m)
instance Scoped scope m => Scoped scope (ReaderT r m) where
type ScopedAs scope (ReaderT r m) = ReaderT r (ScopedAs scope m)
instance Scoped scope m => Scoped scope (StateT s m) where
type ScopedAs scope (StateT s m) = StateT s (ScopedAs scope m)
instance Scoped scope m => Scoped scope (WriterT w m) where
type ScopedAs scope (WriterT w m) = WriterT w (ScopedAs scope m)