Skip to content

Instantly share code, notes, and snippets.

@blitzcode
Created July 5, 2014 12:35
Show Gist options
  • Save blitzcode/d88e9959f9cf0391397d to your computer and use it in GitHub Desktop.
Save blitzcode/d88e9959f9cf0391397d to your computer and use it in GitHub Desktop.
Goto
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