[Haskell-cafe] Re: Pattern matching, and bugs

John Lato jwlato at gmail.com
Sat Dec 19 09:16:43 EST 2009

> From: Felipe Lessa <felipe.lessa at gmail.com>
> On Fri, Dec 18, 2009 at 02:13:02PM +0000, John Lato wrote:
>> So now the program needs a result of some type (String in your
>> example) and gets an undefined, and then immediately crashes
>> with an "Exception - undefined" error.
> I think this is the second time this is said in this thread, but
> please don't as it may confuse the OP.  "undefined"s, including
> those generated by missing cases, do *not* crash the program.
> They also do not *immediately* close the program.  They are
> propagated as exceptions are, however most of the time we write
> programs without explicitly catching them.

Of course you're correct.  I was careful to note that undefined's
generate exceptions, but left out the rest on the assumption that the
OP would be familiar with exception handling and propagation.  But it
is best to be perfectly explicit.

> So the proper wording would be that the "undefined"s propagate
> through the functions and whenever they reach the top function
> (i.e. main), they are caught by the runtime system, which prints
> the String associated with the "undefined" and exits the proccess
> with an error code.
> I should note also that *pure* code *can't* catch those
> "undefined"s.  If they could, then Nasty Things Would Happen(TM)
> and we don't want that.  However IO code may catch them without
> any problem using Control.Exception's functions.

I agree this is an important point, particularly as it's different
from declarative/OOP exception mechanisms.


More information about the Haskell-Cafe mailing list