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

Neil Mitchell ndmitchell at gmail.com
Tue Jun 19 19:07:20 EDT 2007


> > 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?
> Take a look at Catch from Neil Mitchell:
> http://www-users.cs.york.ac.uk/~ndm/catch/ .

Using the released version of Catch on the example you gave:

Checking [1/1]: Main: Pattern match failure in function at 5:1-5:10.
Partial: "Main.f"
Partial: "Main.main"
Partial: "main"
Answer: 0

This says: the error message you will get is about a pattern match on
line 5 (that's where 'f' is in the example program). The list of
partial functions, in some kind of call-stack order, is Main.f, then
Main.main - i.e. your main function calls f which is partial. Answer 0
means "the necessary precondition for safety is false" - or its not
safe at all.

If you turn on logging Catch will additionally tell you that the
precondition on 'f' is that the data structure must be a 'A'
constructed value.



More information about the Haskell-Cafe mailing list