[Haskell-cafe] Re: ANNOUNCE: GotoT-transformers version 1.0
Gregory Crosswhite
gcross at phys.washington.edu
Sat Sep 11 21:16:02 EDT 2010
> 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
More information about the Haskell-Cafe
mailing list