On Thu, Apr 29, 2004 at 06:27:32PM -0500, [EMAIL PROTECTED] wrote:
> Hi,
> While writing monad programs, I sometimes want to do a return as it is in
> imperative program. i.e.,
> do{return 1; return 2} is same as return 1
> 
> Is this possible at all?

Someone already proposed an Error monad, but I think that Continuation
monad is more appropriate, as it's easier to ,,return'' values of
different types. It also allows you to choose the place you want to
,,return'' to.

You'll probably want to use features of other monad, so use a ContT
monad transformer.

Here's an example:

    import Control.Monad.Cont

    code = (\m -> runContT m return) $ do
        x <- callCC $ \exit -> do
            exit 1
            return 2
        lift (print x)

This will print 1, not 2.

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to