Created
July 5, 2014 12:35
-
-
Save blitzcode/d88e9959f9cf0391397d to your computer and use it in GitHub Desktop.
Goto
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
newtype Label r m = Label { runLabel :: ContT r m () } | |
label :: ContT r m (Label r m) | |
label = callCC $ \k -> return $ let x = Label (k x) in x | |
goto :: Label r m -> ContT r m b | |
goto lbl = runLabel lbl >> goto lbl | |
usesGoto :: (Monad m) => ContT r m r -> m r | |
usesGoto = flip runContT return | |
{- | |
usesGoto = flip runContT return | |
label = ContT fix | |
goto label = lift label | |
-} | |
main :: IO () | |
main = usesGoto $ do | |
abc <- label | |
liftIO $ putStrLn "goto" | |
goto abc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment