[Haskell-cafe] Avoiding "Non-exhaustive patterns in function f"
peterv
bf3 at telenet.be
Wed Jun 20 12:15:08 EDT 2007
Super! Would be nice if this gets build into GHC/GHCI :)
-----Original Message-----
From: Neil Mitchell [mailto:ndmitchell at gmail.com]
Sent: Wednesday, June 20, 2007 01:07
To: Felipe Almeida Lessa
Cc: peterv; haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] Avoiding "Non-exhaustive patterns in function f"
Hi
> > 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:
Analysing
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.
Thanks
Neil
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.9.1/854 - Release Date: 19/06/2007
13:12
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.9.1/854 - Release Date: 19/06/2007
13:12
More information about the Haskell-Cafe
mailing list