Skip to content

Instantly share code, notes, and snippets.

@KiJeong-Lim
Created December 28, 2023 01:19
Show Gist options
  • Save KiJeong-Lim/a451cb86cdf287f925f1ea613c1e9651 to your computer and use it in GitHub Desktop.
Save KiJeong-Lim/a451cb86cdf287f925f1ea613c1e9651 to your computer and use it in GitHub Desktop.
early return
module Main where
import Control.Monad.Trans.Class
import Control.Monad.Trans.Cont
foo :: ContT r IO String
foo = callCC $ \k -> do
b <- lift $ readLn
if b then k "early return" else return ()
lift $ putStrLn "Hello world!"
return "return"
main :: IO ()
main = do
res <- evalContT foo
putStrLn res
return ()
ghci> main
True
early return
ghci> main
False
Hello world!
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment