[Haskell] IO, exceptions and error handling

Tim Docker timothy.docker at macquarie.com
Mon Jun 14 12:30:54 EDT 2004

Philippa Cowderoy wrote:

> The ability to fail doesn't need the do notation, just use of 
> return for success - similar for propagating failure.

I'm not sure I understand. Do you mean writing functions

    sqr x | x < 0     = fail "less than zero"
          | otherwise = return (sqrt x)

If so, I don't see how I can use this without either do
or >>=:

    test x = do
       v1 <- sqr x
       v2 <- sqr (x+1)
       return (v1+v2)

I can't (easily) write

    text c = sqr x + sqr (x+1)

which was what I was getting at.


More information about the Haskell mailing list