John Goerzen wrote:

So why do we have:

catchJust :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a

instead of:

catchJust :: (Exception -> Maybe b) -> (c -> a) -> c -> (b -> a) -> a

As I'm sure you have gathered from all the answers you can't have the latter and keep Haskell pure. But there is an interesting alternative (at least theoretically). You could have a function like

mkCatchJust :: IO ((Exception -> Maybe b) -> (c -> a) -> c -> (b -> a) -> a)

And you would use it by

    do
        cj <- mkCatchJust

        ....  cj ....

The cj function can be used in non-IO code and will behave just as you
want.  But you have to create it in the IO monad, since it's behaviour
is not deterministic (especially not in the face of async exceptions).

The tricky thing is to implement it, because cj should really only be
used once.  Why?  Because it has to behave the same way for the same
arguments every time.  This is not easily implemented. :(

        -- Lennart

_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to