[Haskell-beginners] Question re "Pattern match(es) are non-exhaustive"
Mike Meyer
mwm at mired.org
Tue Feb 10 13:18:11 UTC 2015
On Tue, Feb 10, 2015 at 6:58 AM, Joel Neely <joel.neely at gmail.com> wrote:
> {-# OPTIONS_GHC -Wall #-}
>
> sumDigits :: [Integer] -> Integer
> sumDigits [] = 0
> sumDigits (n:ns)
> | n < 10 = n + sumDigits ns
> | n >= 10 = r + sumDigits (q : ns)
> where (q, r) = n `quotRem` 10
>
> sumList :: [Integer] -> Integer
> sumList [] = 0
> sumList (n:ns) = n + sumList ns
>
>
>
ghc can't decide whether or not the tests in the guards are complete or
not. If you rewrite the second condition as "otherwise", it'll recognize
the catch-all and you won't get a warning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150210/c089727b/attachment.html>
More information about the Beginners
mailing list