[Haskell] IO, exceptions and error handling

Keith Wansbrough Keith.Wansbrough at cl.cam.ac.uk
Mon Jun 14 12:41:03 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
> like:
> 
>     sqr x | x < 0     = fail "less than zero"
>           | otherwise = return (sqrt x)

s/fail/error/
s/return//

Then you can easily write

> I can't (easily) write
> 
>     text c = sqr x + sqr (x+1)

You just can't *catch* this outside the IO monad.

--KW 8-)
-- 
Keith Wansbrough <kw217 at cl.cam.ac.uk>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.



More information about the Haskell mailing list