1 import Control.Monad.X.Transformers
3 test00' _ = do a <- local (+1) ask
8 test0' _ = do a <- callCC $ \jmp -> local (+1) ask
12 -- this illustrates an interesting phenomenon.
13 -- if the reader is there before continuations,
14 -- jumping will not undo "local" changes to the environment,
15 -- and they will be seen in the continuation.
16 -- this happens because the jump is within the scope
18 test1' _ = do a <- callCC $ \jmp -> local (+1) (ask >>= jmp)
23 test2' _ = callCC $ \jmp -> tell [1] >> jmp 2
25 -- what should this do?
26 test22' _ = do (a,w) <- callCC $ \jmp -> tell [1] >> listen (jmp (3,[]))
31 output w = do x <- get
36 a <- m -- this is wrong if m jumps as it will delete all output
42 test32' _ = do (a,w) <- callCC $ \jmp -> output "1" >> {-list-} (jmp (3,""))
46 test33' _ = do (a,w) <- callCC $ \jmp -> output "1" >> list (output "7")
52 test3' _ = callCC $ \jmp -> put 1 >> jmp 2
55 test00 = do print =<< (runCont $ runReader 7 $ test00' ())
56 print =<< (runReader 7 $ runCont $ test00' ())
58 test0 = do print =<< (runCont $ runReader 7 $ test0' ())
59 print =<< (runReader 7 $ runCont $ test0' ())
61 test1 = do print =<< (runCont $ runReader 7 $ test1' ())
62 print =<< (runReader 7 $ runCont $ test1' ())
64 test2 = do print =<< (runCont $ runWriter $ test2' ())
65 print =<< (runWriter $ runCont $ test2' ())
67 test3 = do print =<< (runCont $ runStateS 7 $ test3' ())
68 print =<< (runStateS 7 $ runCont $ test3' ())
70 test32 = do print =<< (runCont $ runStateS [] $ test32' ())
71 print =<< (runStateS [] $ runCont $ test32' ())
73 test33 = do print =<< (runCont $ runStateS [] $ test33' ())
74 print =<< (runStateS [] $ runCont $ test33' ())