Non-exhaustive pattern match(es) warning in lambda functions

Simon Peyton-Jones simonpj at microsoft.com
Thu Sep 23 04:40:52 EDT 2010


| For patterns in left hand sides (lhs) of let or where also no warnings
| are issued.
| 
| data Foo = Bar Int | Baz
| 
| test3 :: Foo -> Int
| test3 x = let Bar i = x in i
| 
| Will or should these cases be covered, too?

No, I don't plan to warn about these, which is the case at present.  It's quite common to have let-bindings that are only used sometimes, eg

f xs | null xs = blah
     | otherwise = x+1
     where
       (x:_) = xs

I use this a lot.

S
| 
| Cheers Christian
| 
| >
| > S
| >
| > | -----Original Message-----
| > | From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-
| > | users-bounces at haskell.org] On Behalf Of Mitar
| > | Sent: 21 September 2010 07:44
| > | To: glasgow-haskell-users
| > | Subject: Non-exhaustive pattern match(es) warning in lambda functions
| > |
| > | Hi!
| > |
| > | Why GHC does not warn (with -Wall) about non-exhaustive pattern
| > | match(es) warning in lambda functions? For example, this code:
| > |
| > | data Foo = Bar | Baz
| > |
| > | test1 :: Foo -> IO ()
| > | test1 Bar = return () -- Pattern match(es) are non-exhaustive warning, OK
| > |
| > | test2 :: Foo -> IO ()
| > | test2 = \Bar -> return () -- No pattern match(es) are non-exhaustive, BAD
| > |
| > | I think it would be quite useful to also catch such situations and
| > | issue a warning.
| > |
| > |
| > | Mitar
| > | _______________________________________________
| > | Glasgow-haskell-users mailing list
| > | Glasgow-haskell-users at haskell.org
| > | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
| >
| >
| >
| >
| > _______________________________________________
| > Glasgow-haskell-users mailing list
| > Glasgow-haskell-users at haskell.org
| > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



More information about the Glasgow-haskell-users mailing list