[Haskell-cafe] Re: exceptions vs. Either

André Pang ozone at algorithm.com.au
Fri Aug 6 11:03:24 EDT 2004

On 06/08/2004, at 6:56 PM, MR K P SCHUPKE wrote:

>> After all, Java basically does exactly what you're asking for with
> Java's head/tail would be doing runtime checks if they are throwing 
> exceptions,
> static guarantees mean the program would not be allowed to compile if 
> it broke
> the static guarantees.

As Keith said, Java will check at compile time whether or not you 
handle the exception.  My point is this: it is impossible to check 
whether the exception is "properly" handled.  If you adjust Haskell's 
tail function to return (Maybe [a]) instead of just ([a]), you are 
doing the thing as Java from a pragmatic perspective: you are adding 
information to the type system that tells the programmer the function 
may fail.  You also suffer the same consequence as Java: you have no 
idea whether the programmer properly handles the error situation.

If I am writing a one-shot, never-use-again script that takes 3 minutes 
to write, and I _know_ that I'm not going to be feeding the tail 
function a non-empty list--e.g. because I'm writing a one-shot 
five-minute script to transform a file from one text format to another, 
as is the case for lots of Perl programs--then the extra Maybe type 
just gets in the way.  I'll either ignore the Nothing case, or write 
`case tail foo of ... Nothing -> error "bleh"'.  I will go so far to 
say that such a program can be considered "correct": it does exactly 
what I want it to do, in exactly the circumstances I desire (0 byte 
files being specifically excluded from the circumstances!).

> Which is a bad thing! All programmers always have to consider error 
> conditions,
> if they don't they write buggy code - that's the nature of the beast. 
> I prefer
> making programmers expicitly face the decisions they are making, 
> rather than
> have things implicitly handled in a way that hides what is going on 
> from the
> programmer.

It's a question of whether the library designer should impose their 
will on the library user.  As a library designer, do you feel that you 
are always making the right decision for the library user 100% of the 
time?  I know I never feel like that when I write libraries ...

% Andre Pang : trust.in.love.to.save

More information about the Haskell-Cafe mailing list