On 23 Nov 2004, at 15:51, John Goerzen wrote:

On Tue, Nov 23, 2004 at 04:30:21PM +0000, Keean Schupke wrote:
I am sure this discussion has happened before, but I think for pure
functions, returning Either Error Result is the way to go.

That's certainly possible, but extremely tedious.


It sounds to me like the Either approach is what you are asking for, though?


You want:

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

Can't you write:

catch :: (c -> Either Error a) -> c -> (Error -> a) -> a
catch code value handler =
  case code value of
    Right res -> res
  | Left e -> handler e

..or, to use the either idiom

catch code value handler = either (\res -> res) (\e -> handler e) (code value)

(the extension to catchJust is left to the reader)

The point is : the Either approach is the correct way to represent the notion of 'pure functional exceptions', you don't need language support: and you can build something that looks like language support as combinators?

Jules

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

Reply via email to