Re: Warn about variable patterns which match only a single data constructor
Florian Weimer <[email protected]> Tue, 31 Jan 2012 21:29:11 +0100
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <[email protected]> |
* Matthew Fluet: > 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? The last match (that is, ideally, any variable in a pattern). > 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. Correct. I'm actually worried about this: datatype t = A | C fun i A = 0 | i B = i B Which might have started as this snippet: datatype t = A | B fun i A = 0 | i B = i B Exhaustiveness and redundancy checks under source code edits are a pet peeve of mine, and I would like to get some actual data. ------------------------------------------------------------------------------ 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