[Haskell-cafe] Using the ContT monads for early exits of IO ?
inforichland at gmail.com
Thu Jun 10 11:49:38 EDT 2010
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).
> foo = (`runContT` id) $ do
> dummy <- callCC $ \exit -> forever $ do
> line <- liftIO getLine
> if line == "quit" then exit $ return () else ... -- do whatever
2010/6/10 Günther Schmidt <gue.schmidt at web.de>
> 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
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe