1 2 3 4 5 6 7 8 9 10 11 12 | neverReturns :: IO ()
neverReturns = (`runContT` return) $ do
callCC $ \gotoAfter -> do
lift $ print "before"
gotoAfter ()
lift $ print "never gets here, haha!"
lift $ print "gets here though!"
main :: IO ()
main = do
neverReturns
print "Even at the end of the program, never gets here is never called"
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import Control.Monad.Cont
import Control.Monad.Reader
import Control.Monad.Trans(lift)
neverReturns :: IO ()
neverReturns = (`runContT` return) $ do
callCC $ \gotoAfter -> do
lift $ print "before"
gotoAfter ()
lift $ print "never gets here, haha!"
lift $ print "gets here though!"
main :: IO ()
main = do
neverReturns
print "Even at the end of the program, never gets here is never called"
|
1 2 3 4 | [@ twey peordh ] % ./nr % [P ~/Development/Haskell/#haskell/Peaker/cont/neverReturns ] [J 0 ] [L 758 ]
"before"
"gets here though!"
"Even at the end of the program, never gets here is never called"
|
1 2 3 4 5 | This is the output
"before"
"gets here though!"
"Even at the end of the program, never gets here is never called"
|