[Haskell-cafe] More death to partial functions: Should -fwarn-incomplete-uni-patterns be enabled with -Wall?

Niklas Hambüchen mail at nh2.me
Sun Nov 8 00:10:05 UTC 2015


Hello everyone,

to my dismay, a -Wall compiled program I deployed today crashed with

  Exception: Non-exhaustive patterns in lambda

and I learned from http://dev.stephendiehl.com/hask/ that

  A more subtle case is when implicitly pattern matching with a single
  "uni-pattern" in a lambda expression. The following will fail when
  given a Nothing.

    boom = \(Just a) -> something

  GHC can warn about these cases with the
  -fwarn-incomplete-uni-patterns flag.

And in fact:

  ghci -Wall
  > map (\Nothing -> "ok") [Just 'a']
  ["*** Exception: <interactive>:2:6-21: Non-exhaustive patterns in lambda
  > :set -fwarn-incomplete-uni-patterns
  > map (\Nothing -> "ok") [Just 'a']
  <interactive>:4:6: Warning:
      Pattern match(es) are non-exhaustive

It really surprised me that -fwarn-incomplete-uni-patterns is not
included in -Wall; I've felt really safe with my -Wall so far,
especially about totality and similar things that will almost certainly
lead to crashes.

In an older mail from 2010
(https://mail.haskell.org/pipermail/glasgow-haskell-users/2010-September/019237.html)
I saw Simon mention that it wasn't planned to warn about inexhaustive
patterns like this.

I feel like there has been a strong push towards more totality in the
last years, and I would like to ask if enabling
-fwarn-incomplete-uni-patterns in -Wall may be reconsidered for a coming
next GHC version, or if there are still opponents to that.

Niklas


More information about the Haskell-Cafe mailing list