Gregory Crosswhite <gcross at phys.washington.edu> wrote: > Okay, where that unpost button when I need it... :-) > > So, I hadn't noticed that the script that I copied and pasted didn't > even compile because I was pressing "up enter" at the console to run > it, but had forgotten that I was now working with a script with a new > name and so all I was doing was running a different script over and > over again! Doh. :-) Happens. =) > Anyway, okay, I see your point now. The following script *does* work. > > import Data.List > > import Control.Monad > import Control.Monad.IO.Class > import Control.Monad.Trans.Cont > > goto :: Monad m => ContT r m r -> ContT r m a > goto (ContT m) = ContT $ \_ -> m return > > myComp :: ContT () IO () > myComp = do > input <- liftIO $ putStrLn "Print something (y/n)?" >> getLine > unless ("y" `isPrefixOf` input) $ goto exit > liftIO $ putStrLn "Something." > > input <- liftIO $ putStrLn "Print more (y/n)?" >> getLine > unless ("y" `isPrefixOf` input) $ goto exit > liftIO $ putStrLn "More." > > where > exit = do > liftIO $ putStrLn "Ok, I'm exiting." > return () > > main :: IO () > main = runContT myComp return > > *HOWEVER*, if we replace main with > > main = runContT myComp (const $ putStrLn "I can't wait to print this string!") > > Then the program will be eternally disappointed because it will never > actually get to print that string at the end. It should print the string, if the computation isn't aborted, i.e. if the last continuation, which you specify as an argument to runContT is reached. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex)