To recover from my overly complex previous post, here is a much simply
goto based on existing monad transformers:
goto :: Monad m => ContT r m r -> ContT r m a
goto (ContT m) = ContT $ \_ ->
m return
That doesn't actually work, though. Try running the following script:
import Data.List
import MonadLib
goto :: Monad m => ContT r m r -> ContT r m a
goto (ContT m) = ContT $ \_ -> m return
myComp :: ContT () IO ()
myComp = do
input <- inBase $ putStrLn "Print something (y/n)?" >> getLine
unless ("y" `isPrefixOf` input) $ goto exit
inBase $ putStrLn "Something."
input <- inBase $ putStrLn "Print more (y/n)?" >> getLine
unless ("y" `isPrefixOf` input) $ goto exit
inBase $ putStrLn "More."
where
exit = do
inBase $ putStrLn "Ok, I'm exiting."
return ()
main :: IO ()
main = runContT return myComp
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe