/usr/lib/hugs/packages/mtl/Control/Monad/Cont.hs is in libhugs-mtl-bundled 98.200609.21-5.4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | {-# OPTIONS -fallow-undecidable-instances #-}
-- Search for -fallow-undecidable-instances to see why this is needed
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.Cont
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : non-portable (multi-parameter type classes)
--
-- Continuation monads.
--
-----------------------------------------------------------------------------
module Control.Monad.Cont (
MonadCont(..),
Cont(..),
mapCont,
withCont,
ContT(..),
mapContT,
withContT,
module Control.Monad,
module Control.Monad.Trans,
) where
import Prelude
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Reader
import Control.Monad.Writer
import Control.Monad.State
import Control.Monad.RWS
class (Monad m) => MonadCont m where
callCC :: ((a -> m b) -> m a) -> m a
-- ---------------------------------------------------------------------------
-- Our parameterizable continuation monad
newtype Cont r a = Cont { runCont :: (a -> r) -> r }
instance Functor (Cont r) where
fmap f m = Cont $ \c -> runCont m (c . f)
instance Monad (Cont r) where
return a = Cont ($ a)
m >>= k = Cont $ \c -> runCont m $ \a -> runCont (k a) c
instance MonadCont (Cont r) where
callCC f = Cont $ \c -> runCont (f (\a -> Cont $ \_ -> c a)) c
mapCont :: (r -> r) -> Cont r a -> Cont r a
mapCont f m = Cont $ f . runCont m
withCont :: ((b -> r) -> (a -> r)) -> Cont r a -> Cont r b
withCont f m = Cont $ runCont m . f
-- ---------------------------------------------------------------------------
-- Our parameterizable continuation monad, with an inner monad
newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r }
instance (Monad m) => Functor (ContT r m) where
fmap f m = ContT $ \c -> runContT m (c . f)
instance (Monad m) => Monad (ContT r m) where
return a = ContT ($ a)
m >>= k = ContT $ \c -> runContT m (\a -> runContT (k a) c)
instance (Monad m) => MonadCont (ContT r m) where
callCC f = ContT $ \c -> runContT (f (\a -> ContT $ \_ -> c a)) c
instance MonadTrans (ContT r) where
lift m = ContT (m >>=)
instance (MonadIO m) => MonadIO (ContT r m) where
liftIO = lift . liftIO
-- Needs -fallow-undecidable-instances
instance (MonadReader r' m) => MonadReader r' (ContT r m) where
ask = lift ask
local f m = ContT $ \c -> do
r <- ask
local f (runContT m (local (const r) . c))
-- Needs -fallow-undecidable-instances
instance (MonadState s m) => MonadState s (ContT r m) where
get = lift get
put = lift . put
-- -----------------------------------------------------------------------------
-- MonadCont instances for other monad transformers
instance (MonadCont m) => MonadCont (ReaderT r m) where
callCC f = ReaderT $ \r ->
callCC $ \c ->
runReaderT (f (\a -> ReaderT $ \_ -> c a)) r
instance (MonadCont m) => MonadCont (StateT s m) where
callCC f = StateT $ \s ->
callCC $ \c ->
runStateT (f (\a -> StateT $ \s' -> c (a, s'))) s
instance (Monoid w, MonadCont m) => MonadCont (WriterT w m) where
callCC f = WriterT $
callCC $ \c ->
runWriterT (f (\a -> WriterT $ c (a, mempty)))
instance (Monoid w, MonadCont m) => MonadCont (RWST r w s m) where
callCC f = RWST $ \r s ->
callCC $ \c ->
runRWST (f (\a -> RWST $ \_ s' -> c (a, s', mempty))) r s
mapContT :: (m r -> m r) -> ContT r m a -> ContT r m a
mapContT f m = ContT $ f . runContT m
withContT :: ((b -> m r) -> (a -> m r)) -> ContT r m a -> ContT r m b
withContT f m = ContT $ runContT m . f
|