[Haskell-cafe] Avoiding "Non-exhaustive patterns in function f"

Stefan O'Rear stefanor at cox.net
Tue Jun 19 17:55:14 EDT 2007

On Tue, Jun 19, 2007 at 11:03:46PM +0200, peterv wrote:
> Haskell is known for its very strong static type checking, which eliminates
> a lot of runtime errors.
> But the following simple program crashes at runtime:
> data D = A | B
> f A = True
> main = print (f B)
> I understand this has nothing to do with type checking, but why can't the
> compiler give a warning about this? Or is this by design or because it is
> impossible to check with more complex recursive data types?

Like all good UNIX compilers, GHC will only print warnings if you ask it
to, with -Wincomplete-patterns (iirc).  -Wall enables most of them, the
full list is in The Glorious Glasgow Haskell Compilation System User's
Guide (a valuable read!)


More information about the Haskell-Cafe mailing list