[MLton] cvs commit: improved type constructor names in type errors

Matthew Fluet fluet@cs.cornell.edu
Tue, 30 Dec 2003 18:42:39 -0500 (EST)

> > Ocaml has a pattern-matcher which reports unexhaustive pattern mathces
> > with an example of a pattern there is missing. a) Would this be a
> > thing that would be worthy to add, and b) hard to add? I am not sure
> > I want that, because I have not generally found any use for it. I just
> > mention it, so it is not forgotten.
> It seems like a good idea to me, so I added it.  Thanks for the
> suggestion.

Is there an (easy) way to get _all_ missing patterns?  The case I'm
thinking of is:

fun first l =
  case l of
    (SOME x)::_ => x

I'm worried that reporting a missing pattern of nil is worse than
reporting nothing.  You may convince yourself that first will never be
called on the empty list, and thereafter live with the warning that the
function is nonexhaustive, but miss the fact that a non-empty list might
still result in a Match exception.  (The current message says that the
pattern ::(NONE, _) is missing, so that's o.k., but you get the idea.)

The other annoyance is that when fixing a pattern match that you believe
is exhaustive, the edit/type-check cycle for each missing pattern can be
tedious, not to mention missing the big picture.

One possibility is to get a missing pattern, then throw it back into the
match, and see what next pattern pops out as missing.  I looked at the
code for the match compiler a little, and it wasn't obvious to me how to
extend the example pattern into a list of examples.