[Haskell] IO, exceptions and error handling
John Meacham
john at repetae.net
Mon Jun 14 18:43:20 EDT 2004
On Mon, Jun 14, 2004 at 05:41:03PM +0100, Keith Wansbrough wrote:
> > 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//
better yet,
import Control.Monad.Identity
sqr' x = runIdentity (sqr x)
now sqr' behaves exactly as if you used 'error' and direct code, but the
monadic version is still available for those that care about it.
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell
mailing list