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
|
{-# LANGUAGE ScopedTypeVariables #-}
import Prelude hiding (log)
import Control.Monad.Trans.Loop
import Control.Exception
import Control.Monad.Reader
import Control.Monad.Writer
test1 :: IO ()
test1 =
foreach [1..4] $ \(i :: Int) -> do
let log msg = liftIO $ putStrLn $ "test1: " ++ show i ++ ": " ++ msg
logMaskingState = do
b <- lift getMaskingState
log $ "getMaskingState: " ++ show b
logMaskingState
liftLocalLoopT mask_ $ do
logMaskingState
when (i == 3) $ do
log "continue"
continue
logMaskingState
-- This test is interesting because we're using mtl's 'local', which in this
-- context walks up the WriterT too.
test2 :: IO ()
test2 =
mapM_ putStrLn $
flip runReader (0 :: Int) $
execWriterT $
foreach [1..4] $ \(i :: Int) -> do
let log msg = lift $ tell ["test2: " ++ show i ++ ": " ++ msg]
logAsk = do
n <- lift ask
log $ "ask: " ++ show n
logAsk
liftLocalLoopT (local (+1)) $ do
logAsk
when (i == 3) $ do
log "continue"
continue
logAsk
|