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

Felipe Lessa felipe.lessa at gmail.com
Fri Dec 18 09:43:10 EST 2009


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.

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.

HTH and clarifies things,

--
Felipe.


More information about the Haskell-Cafe mailing list