Non exhaustive pattern match not flagged?

Hello, I am using the GHC compiler with the -W flag. When I compile: f :: [a] -> [b] -> Int --f [] _ = error "undefined for empty array" f _ [] = error "undefined for empty array" f (_:xs) (_:ys) = length xs + length ys I get a warning: Warning: Pattern match(es) are non-exhaustive In an equation for `f': Patterns not matched: [] (_ : _) as expected. But for: bigrams :: [a] -> [[a]] --bigrams [] = [] bigrams [_] = [] bigrams xs = take 2 xs : bigrams (tail xs) I don't. Why is the first predicate not detected as missing? TIA, Hugo F.

On Mon, 17 Oct 2011 17:39:49 +0200, Hugo Ferreira
f :: [a] -> [b] -> Int --f [] _ = error "undefined for empty array" f _ [] = error "undefined for empty array" f (_:xs) (_:ys) = length xs + length ys
I get a warning:
Warning: Pattern match(es) are non-exhaustive In an equation for `f': Patterns not matched: [] (_ : _)
as expected. But for:
bigrams :: [a] -> [[a]] --bigrams [] = [] bigrams [_] = [] bigrams xs = take 2 xs : bigrams (tail xs)
I don't. Why is the first predicate not detected as missing?
The pattern in the line bigrams xs = take 2 xs : bigrams (tail xs) matches any list, even empty lists Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html --

On 10/17/2011 04:53 PM, Henk-Jan van Tuyl wrote:
On Mon, 17 Oct 2011 17:39:49 +0200, Hugo Ferreira
wrote: f :: [a] -> [b] -> Int --f [] _ = error "undefined for empty array" f _ [] = error "undefined for empty array" f (_:xs) (_:ys) = length xs + length ys
I get a warning:
Warning: Pattern match(es) are non-exhaustive In an equation for `f': Patterns not matched: [] (_ : _)
as expected. But for:
bigrams :: [a] -> [[a]] --bigrams [] = [] bigrams [_] = [] bigrams xs = take 2 xs : bigrams (tail xs)
I don't. Why is the first predicate not detected as missing?
The pattern in the line bigrams xs = take 2 xs : bigrams (tail xs) matches any list, even empty lists
Thank you. Hugo F.
Regards, Henk-Jan van Tuyl
participants (2)
-
Henk-Jan van Tuyl
-
Hugo Ferreira