Re: Warn about variable patterns which match only a single data constructor

Matthew Fluet <[email protected]> Mon, 30 Jan 2012 21:46:19 -0500
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <CAMrhFL5VmfDXXBLcbTW+8-2+x=9w1tiAS1iLdsM09DVz4kg8ag@mail.gmail.com>
On Sun, Jan 29, 2012 at 10:12 AM, Florian Weimer <[email protected]> wrote:
> I'm working on patch which adds another pattern match warning,
> intended to cover this case:
>
> datatype t = A | B
>
> fun i A = 0
>  | i C = 1
>
> As it stands, this produces many false positives.  I guess the warning
> should fire only if the variable pattern matches a single,
> parameter-less data constructor.  Any ideas how to implement that?

I'm not quite sure that I follow the situation that is being warned
about.  Is it that the last match matched only one constructor or that
the whole match only (explicitly) matched one constructor?

It might be worth noting that the "warnUnused true" warning would warn
about the unused variable "C" in the above.  That seems to usually
cover the situations where you meant to use a constructor in a
pattern, but mistakenly used a variable.

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d