This tag concerns pattern match coverage errors or warnings in functional programming languages with algebraic data types and pattern matching. Questions with this tag can be about why a compiler detects missing patterns or why missing patterns cause an error at run time.
Questions tagged [non-exhaustive-patterns]
85 questions
3
votes
2 answers
Non-exhaustive pattern matches only because I left off `otherwise =`?
I wrote a simple program in Haskell that plays the guessing game described in The Rust Programming Language book:
Here’s how it works: the program will generate a random integer between 1 and 100. It will then prompt the player to enter a guess.…

evanrelf
- 303
- 3
- 12
3
votes
2 answers
Pattern match(es) are non-exhaustive
I'm trying to create a function that eliminates multiples of a given Integer from a list of Integers, in the form multiples x [y], where x is the given Integer, and y is the list.
Here's what I have:
multiples :: Integer -> [Integer] ->…

Erakura
- 35
- 1
- 5
3
votes
2 answers
Pattern Match Fail when `function [] _ = ...; function _ [] = ...` syntax is omitted
Though disjoint exhausts all possible patterns in its guard conditions, Haskell gives me a PatternMatchFail error when running it.
disjoint :: (Ord a) => [a] -> [a] -> Bool
disjoint l@(x:xs) r@(y:ys)
| null l || null r = True
| x == y …

Nicholas Montaño
- 935
- 10
- 24
3
votes
1 answer
Haskell: Fix non-exuastive patterns in function
I have a program that traverses an AST and returns a map of the functions and variables used and how many times they occurred. Here it is:
import Data.Map
import Language.Haskell.Exts.Syntax
increment :: Ord a => a -> Map a Int -> Map a…

user2548080
- 187
- 7
2
votes
1 answer
Make Compile Fail on Non-Exhaustive Match in Scala 3
Since Scala 2.13, -Wconf compiler flag allows to precisely control over which warnings should be handled as errors. The configuration string for -Wconf however is not always the same when migrating to Scala 3.
In particular, I'm struggling to find…

alessandro candolini
- 617
- 6
- 13
2
votes
1 answer
Multiple assignment from a vector to individual variables
In my test suite I am frequently writing code such as
val Vector(socialSci, humanities, pureSci, pureApplSci) = foo(someValue)
foo obviously returns a (short) Vector but I'd like to have names for each of the values. It's not always four items…

bwbecker
- 1,031
- 9
- 21
2
votes
1 answer
Non Exhaustive Patterns in function
I'm writing a program in Haskell that can pretty print a table and do basic queries on it. The following function is a snippet of the code which prints a table:
printTable :: Table -> [String]
printTable table@(header:rows) = [addLine] ++ addHeader…

Felix
- 147
- 2
- 10
2
votes
1 answer
Haskell, Non-exhaustive patterns in function - way for checking this condition
Is there exist any way to check if my code contains: Non-exhaustive patterns in function ? Maybe some flag for compiler ?
user6023611
2
votes
2 answers
Haskell: Non-exhaustive patterns with Sieve of Eratosthenes
I wanted to use this code of Sieve of Eratosthenes from this page: http://en.literateprograms.org/Sieve_of_Eratosthenes_(Haskell)#chunk def:primes_naive
Only a bit modified, so it only shows the primes up to a number:
primes :: Integral a => a ->…

Rainflow
- 161
- 1
- 2
- 5
2
votes
1 answer
Haskell non-exhaustive patterns in function with `otherwise`
I am using the following function:
combinations :: Int -> [a] -> [[a]]
combinations k xs = combinations' (length xs) k xs
where combinations' n k' l@(y:ys)
| k' == 0 = [[]]
| k' >= n = [l]
| null l = []
…

Marcin
- 380
- 3
- 20
2
votes
3 answers
Non-exhaustive pattern in function-Haskell
I've written a function, that Inserts an Element into a binary Tree, but every time I try to run it, I get the a non-exhaustive pattern in function.
type Eintrag = (Person, Anschrift, SozNr)
data Tree = Nil | Node Eintrag Tree Tree deriving (Eq,…

Irina Avram
- 1,492
- 2
- 20
- 35
2
votes
1 answer
Calculating the length of an array in haskell - non exhaustive patterns error
I've searched around on here and on the net in general and I can't find anything that seems to be answering this question. I've only just starting playing around with Haskell for a module at university and I'm having an issue defining a function to…

leachrode
- 303
- 3
- 15
2
votes
2 answers
Why does Scala 2.10 give 'match may not be exhaustive' warning when matching on singleton types?
In Scala 2.10.0-M4
object X
def f(e: Either[Int, X.type]) = e match {
case Left(i) => i
case Right(X) => 0
}
gives:
warning: match may not be exhaustive.
It would fail on the following input: Right()
Is this correct? Surely the match is…

Scott Morrison
- 3,100
- 24
- 39
2
votes
1 answer
Disable "Non-exhaustive patterns in case" in GHCI
I am reading the paper "Monad Transformers Step by Step" and making my way through the examples.
In the eval0 example, there is an intentional non-exhaustive pattern in a case expression:
eval0 :: Env -> Exp -> Value
eval0 env (Lit i) = IntVal…

Ralph
- 31,584
- 38
- 145
- 282
1
vote
1 answer
Unreachable case except for null in scala
I have the following helper function. I am trying to create a word frequency List. (a,b,a) => [(a,2),(b,1)]:
def add_to_lop(c:Char, lop: List[(Char, Int)]):List[(Char, Int)] = {
lop match {
case List() => List((c,1))
case (c,…

figs_and_nuts
- 4,870
- 2
- 31
- 56