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
1
vote
0 answers
Why am I not being warned about a non-exhaustive match?
Compiling this code does not result in any warnings about exhaustive pattern matches.
package example
object Hello extends App {
class Problem extends Exception {
override def getCause() : Throwable = new NotImplementedError("I'm not done")
…

Tim Stewart
- 5,350
- 2
- 30
- 45
1
vote
2 answers
Can this prime sieve code be further simplified in Haskell?
The code works well
primes = next [2 ..]
where
next (p : ps) = p : next ts
where
ts = filter (\x -> mod x p /= 0) ps
Just GHCI think there is a incomplete patter in next.
Well, this is correct from a grammatical point of…

Sid
- 13
- 3
1
vote
1 answer
Non-exhaustive pattern matching?
I have the following code:
data Tree = Leaf | Node Int Tree Tree
deriving (Eq, Show, Read, Ord)
insert :: Int -> Tree -> Tree
insert n Leaf = Node n Leaf Leaf
insert n tree@(Node num lt rt)
| n < num = Node num (insert n lt)…
user8525706
1
vote
2 answers
Recursion error at my encode function from “99 questions in Haskell”
The problem is:
“Run-length encoding of a list. Use the result of problem P09 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as lists (N E) where N is the number of duplicates…

João Paulo Andrade
- 97
- 6
1
vote
1 answer
Haskell Exception Non-exhaustive patterns on String
My Function is
import System.IO
import Debug.Trace
main :: IO ()
main = do
datei <- openFile "palindrom.txt" ReadMode
palin <- hGetContents datei
putStrLn $ unlines [ check x | x <- lines palin]
check :: String…

logn
- 113
- 4
1
vote
1 answer
Missing pattern in inserts function
I have this function inserts where
inserts 1 [2,3] = [[1,2,3],[2,1,3],[2,3,1]]
here's the definition (straight from Algorithm Design with Haskell by Bird and Gibbons)
inserts :: a -> [a] -> [[a]]
inserts x [] = [[x]]
inserts x (y:ys) = (x:y:ys) :…

JaviRdrgz
- 21
- 3
1
vote
1 answer
How to measure the size of a MultTree in Haskell?
I'm quite new to Haskell and therefore not very familiar with it.
The following method is to measure the size of a MultTree.
A MultTree includes Index nodes that contain two Int's and can have an arbitrary amount of children. Then there's also Data…

Smite
- 59
- 4
1
vote
2 answers
Non-exhaustive patterns in function len
I'm writing this function len which calculates the length of a list in GHCi.
len [] = 0
len [x] = 1
len (x:xs) = 1 + len xs
I tried to call the function with [] as the argument but the error Exception: Non-exhaustive patterns in function len hit…

Py thon
- 23
- 3
1
vote
3 answers
Higher-order, partial function — where to place @unchecked annotation?
I've a piece of code for which I get a "match may not be exhaustive" warning from Scala 2.13.4, and I'd like to suppress that warning with the @unchecked annotation. Unfortunately, all my attempts of inserting @unchecked merely resulted in syntax…

Malte Schwerhoff
- 12,684
- 4
- 41
- 71
1
vote
2 answers
Non exhaustive patterns in Haskell recursion
I'm trying to write a function which gives me the distance between every district in my list. The function distance gives me the distance between two districts as an Int from a set array, and I want to run through the whole list to sum up the…

green tea
- 87
- 7
1
vote
1 answer
Toggle every element in a list in haskell
I have to write a function that toggles a list of given Booleans for example :
input : toggle [True,False,False]
output: [False,True,True]
This is what I came up with
toggle :: [Bool] -> [Bool]
toggle [a] = not a:[a]
toggle [] = []
And I keep…

green tea
- 87
- 7
1
vote
3 answers
Non-exhaustive Error in Basic Haskell Function
I'm new to Haskell and trying to put together a simple function to check whether or not two numbers are equal. This compiles, but when I try out a test of the program, it says that this is non-exhaustive. I don't understand how it can be…

Larissa
- 13
- 3
1
vote
1 answer
Haskell Data Declaration : Find sum of Leaves in a binary Tree
Here is a binary tree, and i am trying to calculate the sum of the leaves
-1
/ \
-5 10
/ \
-4 30
/ \
13 17
The data declaration is given.
data Tree = TNode Int [ Tree…

John
- 135
- 6
1
vote
1 answer
Type parameter circumvents match exhaustivity warning
Why does type parameter bound by sealed type seem not to raise exhaustivity warning
sealed trait A
case class B() extends A
case class C(i: Option[Int]) extends A
def f[T <: A](a: T) =
a match {
case B() =>
case C(None) =>
…

Mario Galic
- 47,285
- 6
- 56
- 98
1
vote
2 answers
Count the number of values in a nested list that are greater and less than certain values
I'm working on a function for a homework problem that counts the number of values in a list for which the values are greater than v1 and less than v2. I've put something together that works but only in a specific case. When I try something else I…

Larry.Fish
- 123
- 1
- 8