Created
December 28, 2023 01:19
-
-
Save KiJeong-Lim/a451cb86cdf287f925f1ea613c1e9651 to your computer and use it in GitHub Desktop.
early return
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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