On Thu, Nov 25, 2004 at 07:52:43PM +0100, Lennart Augustsson wrote:
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)
How is that different from this? mkReadFile :: IO (FilePath -> String) This is wrong. Even if I get a function as a result of an IO computation, I expect that function to be pure.
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).
IO monad shouldn't be used to create non-deterministic functions. The whole point in using IO monad is that functions stay pure, regardless of their origin. Best regards, Tomasz