[MLton] Catching redundant pattern matches
Stephen Weeks
MLton@mlton.org
Sun, 12 Dec 2004 11:29:16 -0800
> I have a little lump of code, which is like this:
...
>
> Of course, the last pattern ([], []) is redundant in the above and the
> code is dead wrong since the pattern should be the first. My concern
> is that MLton did not warn about this, while Moscow ML did:
I am surprised MLton did not warn about this, as there is code to
point out redundant matches. As an experiment, I tried compiling the
following code with MLton.
val () =
case ([], []) of
([], regs) => ()
| (s :: ss, r :: rs) => ()
| (ss, []) => ()
| ([], []) => ()
MLton gave the following error.
Warning: z.sml 2.4.
Case has redundant rules.
rules: ([], []) => ()
in: case ([], []) of (([], regs)) => (( ... (()) | (([], [])) => (())
Since MLton's match compiler ignores the right-hand-sides entirely, I
believe you should see a similar error message in your code.
The only explanation I can offer for why you didn't see the warning is
that MLton only reports nonexhaustive and redundant matches if there
are no type errors in the code. Perhaps your code had other type
errors?
We should document this somewhat surprising aspect of MLton somewhere.
It's not so easy to fix, but I'll think about it.