module Control.Comonad.Trans.Discont.Memo
(
Discont
, discont
, runDiscont
, DiscontT
, discontT
, runDiscontT
) where
import Data.Functor.Identity
import Control.Comonad
import Control.Comonad.Trans.Class
#ifdef __GLASGOW_HASKELL__
import Data.Typeable
instance (Typeable s, Typeable1 w) => Typeable1 (DiscontT s w) where
typeOf1 dswa = mkTyConApp discontTTyCon [typeOf (s dswa), typeOf1 (w dswa)]
where
s :: DiscontT s w a -> s
s = undefined
w :: DiscontT s w a -> w a
w = undefined
discontTTyCon :: TyCon
discontTTyCon = mkTyCon "Control.Comonad.Trans.Discont.Memo.DiscontT"
#endif
type Discont s = DiscontT s Identity
data DiscontT s w a = DiscontT (w s -> a) (w s) a
discont :: (s -> a) -> s -> Discont s a
discont f s = DiscontT (f . runIdentity) (Identity s) (f s)
discontT :: (w s -> a) -> w s -> DiscontT s w a
discontT f s = DiscontT f s (f s)
runDiscont :: Discont s a -> (s -> a, s)
runDiscont (DiscontT f (Identity s) _) = (f . Identity, s)
runDiscontT :: DiscontT s w a -> (w s -> a, w s)
runDiscontT (DiscontT f s _) = (f, s)
instance Functor (DiscontT s w) where
fmap g (DiscontT f ws a) = DiscontT (g . f) ws (g a)
instance Extend (DiscontT s w) where
duplicate (DiscontT f ws _) = discontT (discontT f) ws
instance Comonad (DiscontT s w) where
extract (DiscontT _ _ a) = a
instance ComonadTrans (DiscontT s) where
lower (DiscontT f s _) = extend f s