[Hugs-users] Pattern match failure leads to lots of output

Ross Paterson ross at soi.city.ac.uk
Fri Sep 1 19:20:19 EDT 2006


On Fri, Sep 01, 2006 at 11:00:27PM +0100, Neil Mitchell wrote:
> >OK, that gives:
> >
> >        pattern match failure: g_v1624 (Num__sc0_Num instNum_v32) 
> >        (Maybe2_Just2 (Maybe1_Just1 (Num_fromInt instNum_v32 1))) 
> >        Maybe2_Nothing2
> 
> Before any patches? For me with the May 2006 WinHugs, that gives output 
> forever.

How odd.  That's what I get with Mar 2005, May 2006 and my build from last
week.  The difference will be hidden if we stop printing dictionaries,
but it is a bit disconcerting.

> >after my patch:
> >
> >        pattern match failure: g (Just2 (Just1 (fromInt 1))) Nothing2
> >
> >which is almost readable.  Maybe I should hide fromInt/fromDouble too.
> 
> the fromInt would be nice to be hidden, but not really a problem.

It's probably too much trouble.

> The one thing I don't like about that simplification is that g_v162 ->
> g. When I see g_v162 thats kind of vague, but its definately saying "a
> child of g" - as I read it. Now you loose the distinction between g
> and child of g.

Yes, I went too far there -- now undone.

> What would of course be lovely would be g_f, for cases where g has a
> named inner function that is crashing. I'm not sure how much work that
> is to add though.

So far we've been using what's in the Hugs runtime structures, and that
doesn't include the names of inner functions.

> Even better would be a stack trace (showing the equivalent strict
> stack trace), but I realise thats probably a large change :)

What's happening is that pattern match failure throws a PatternMatchFail
exception (from Control.Exception).  Hugs adds a wrapper around
any expression you evaluate to catch any exception and print it.

A PatternMatchFail exception has a String parameter.  In a compiler,
that will typically be the source coordinates of the failing match.
In an interpreter, we have a representation of the expression we were
trying to evaluate, so we turn that into a string (without further
evaluating the expression).  The stack is probably too much trouble.

Note that because it's just another Exception, you can manipulate it
in Haskell.  You can catch, print and re-throw the exception yourself,
or use mapException to add stuff to the String, etc.



More information about the Hugs-Users mailing list