[Haskell-cafe] exceptions vs. Either
quinn at burn.ofb.net
Tue Aug 3 12:59:44 EDT 2004
> A lot of programming errors come from failure to correctly validate.
This was actually nicely illustrated in my program: I assumed that digitToInt
accepted '0'..'9' and wanted to rely on it throwing. After puzzling over
out of range errors (other functions expected digitToInt to be in the 0..9
range) I figured it out and inserted an explicit check. Unfortunately there
is no static check for pre and post conditions, unless you manually add them
to the type system, as you suggest. But that's work ;)
Wrting a monad bind for Either that returns Left immediately and binds Right
would make Either style error propagation easier. But it seems like it would
do a' <- checka a
b' <- checkb b
return $ process a' b'
is rather messier looking than 'process (checka a) (checkb b)'. It doesn't
really matter what order 'a' and 'b' are checked, what I really want is the
monad-style magic plumbing. I suppose I should just wrap 'process' in a
liftM2 and stop worrying about it.
> Of course you must make sure you don't write more than
> one constructor function for ValidInt. This suggests a
Can't you do this at the module level by exporting the ValidInt type, but not
the constructor? Of course, then you have to stick it in its own module, and
simple range validation is getting even more heavyweight...
In response to the "mysterious head exceptions" thread, isn't there a way to
compile with profiling and then get the rts to give a traceback on exception?
More information about the Haskell-Cafe