
Günther, This is definitely one way to do it. If you want to be able to "quit" the IO action in the middle of a lengthy computation, that is one way that I, personally, find very straightfoward. You can find an example of this in my Advgame package on Hackage, which uses this method to quit running the main action (although I could have used a conditional to determine whether to continue running the main loop, but continuations are more fun :P). Small example:
foo = (`runContT` id) $ do dummy <- callCC $ \exit -> forever $ do line <- liftIO getLine if line == "quit" then exit $ return () else ... -- do whatever else here...
Cheers,
- Tim
2010/6/10 Günther Schmidt
Hi everyone,
I'm about to write a rather lengthy piece of IO code. Depending on the results of some of the IO actions I'd like the computation to stop right there and then.
Now I know in general how to write this but I'm wondering if this is one of those occasions where I should make use of the Cont monad to make an early exit.
Günther
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe