RE: [Haskell-cafe] Some random newbie questions

| * As far as I can determine, there is no way to check pattern matches for | exhaustiveness. Coming from OCaml, this feels like losing a significant | safety net! How do people program so as not to be getting dynamic match | failures all the time? GHC has -fwarn-incomplete-patterns and -fwarn-overlapped-patterns. But the code implementing these checks is old and crufty, and the warnings are sometimes a bit wrong -- at least when guards and numeric literals are involved. I think they are accurate when you are just using "ordinary" pattern matching. Cleaning up this bit of GHC is a long-standing to-do item, if anyone feels motivated to undertake it. It's a well-defined task, with plenty of well-written papers explaining how to do it -- but it's tricker than it seems at first! Simon

On Fri, 7 Jan 2005, Simon Peyton-Jones wrote:
| * As far as I can determine, there is no way to check pattern matches for | exhaustiveness. Coming from OCaml, this feels like losing a significant | safety net! How do people program so as not to be getting dynamic match | failures all the time?
GHC has -fwarn-incomplete-patterns and -fwarn-overlapped-patterns. But the code implementing these checks is old and crufty, and the warnings are sometimes a bit wrong -- at least when guards and numeric literals are involved. I think they are accurate when you are just using "ordinary" pattern matching.
Cleaning up this bit of GHC is a long-standing to-do item, if anyone feels motivated to undertake it. It's a well-defined task, with plenty of well-written papers explaining how to do it -- but it's tricker than it seems at first!
What about dropping Guards? :-) Are they necessary? Do they lead to more readable source code? Do they lead to more efficient code? I could perfectly live without them up to now.

Henning Thielemann wrote:
What about dropping Guards? :-) Are they necessary? Do they lead to more readable source code? Do they lead to more efficient code? I could perfectly live without them up to now.
I hardly need guards too, but their advantage is that they let pattern matching fail, resulting in trying out following patterns. case l of [i] | i /= 0 -> (/i) _ -> error "a single message here for all other cases" Cheers Christian
participants (3)
-
Christian Maeder
-
Henning Thielemann
-
Simon Peyton-Jones