RE: [Haskell] IO, exceptions and error handling
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) 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. Tim
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@cl.cam.ac.uk> http://www.cl.cam.ac.uk/users/kw217/ University of Cambridge Computer Laboratory.
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⑈
participants (3)
-
John Meacham -
Keith Wansbrough -
Tim Docker