[Hat] Pattern match errors in do?
Olaf Chitil
O.Chitil at kent.ac.uk
Wed Jul 5 14:11:52 EDT 2006
I can explain this.
A pattern match failure in a "do" will call "fail" (not "error" as other
pattern match failures do). This is the "fail" of the IO monad, which
calls "ioError". And "ioError" raises an exception. This exception is
caught by a "catch" that Hat has put around "main" and that records the
exception in the trace file and terminates the computation. However, for
raising and catching an exception the standard Haskell functions are
used, so no information about which expression raised the exception is
actually passed to the "catch" around main. That's why it cannot write
anything about the origin of the exception in the trace.
An idea that comes to my mind is that every expression raising an
exception could record itself in a global variable in C land. So when
the outermost "catch" catches an exception, it can read the origin from
this global variable. There is no problem with normal "catch" functions
in user programs.
It just isn't very nice and it wouldn't work with concurrency. Hat
currently doesn't work with concurrency, but I believe currently
concurrency could be done in principle by removing the shadow stack,
which is only there for optimisation, but not strictly necessary. I
cannot think of any solution that would deal with exceptions and work
with concurrency. Any suggestions?
Ciao,
Olaf
Malcolm Wallace wrote:
>"Neil Mitchell" <ndmitchell at gmail.com> wrote:
>
>
>
>>Running Main without any arguments via Hat gives me a trace, and the
>>error message:
>>
>>
>>>Error: pattern-match failure in do expression
>>>
>>>
>>Running hat-stack Main.hat gives me:
>>
>>
>>>Tracefile "Main.hat" contains no reference to a program error.
>>>
>>>
>
>Very strange. The tracefile contains the error message (at the end),
>and an explicit reference to it (in bytes 8-11). But it contains no
>reference (in bytes 4-7) to the expression that triggered the error, and
>so hat-stack quite reasonably complains.
>
>It looks like the library code to trap the error and tidy up the
>tracefile might have a bug.
>
>Regards,
> Malcolm
>_______________________________________________
>Hat mailing list
>Hat at haskell.org
>http://www.haskell.org/mailman/listinfo/hat
>
>
More information about the Hat
mailing list