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
0
votes
1 answer
Succinct way to use GADTs for exhaustiveness-checking in Scala?
I'm looking for the same behavior as the following OCaml code, where the compiler understands the match is exhaustive because we've expressed that the two scrutinees must have the same type:
type circle
type rectangle
type _ figure =
| Circle :…

Max Heiber
- 14,346
- 12
- 59
- 97
0
votes
1 answer
exhaustive-deps infinite loop with function dependant on component state
Given the following example
const SettingsLayout = () => {
const [tabs, setTabs] = useState(SettingsNavigation);
const router = useRouter();
const updateActiveTab = useCallback(
(pathname) => {
setTabs(
tabs.map((tab: Tab)…

HYAR7E
- 194
- 2
- 10
0
votes
1 answer
Why is Haskell lookup function causing Non-Exhaustive pattern error on custom data type?
Anyone know why this is causing the error Non-exhaustive patterns in function getCityPopulation?
type Name = String
type Coordinates = (Int, Int)
type Pop = Int
type TotalPop = [Pop]
type City = (Name, (Coordinates, TotalPop))
testData ::…

Alex
- 394
- 1
- 4
- 15
0
votes
1 answer
How do I get rid of the non-exhaustive patterns error in Haskell?
I'm very new to Haskell so I'm afraid I haven't fully understood how it works yet. Following method is supposed to determine whether a matrix is an actual matrix or not.
isMatrix :: [[Int]] -> Bool
isMatrix [[x]] = True
isMatrix [x] = True
So…

Smite
- 59
- 4
0
votes
1 answer
Pattern matching failing for valid pattern
I have the following code:
import Debug.Trace (trace)
mtrace :: Show a => String -> a -> a
mtrace msg value =
trace (msg ++ show value) value
isVowel :: Char -> Bool
isVowel = (`elem` "AEIOU")
vowelSlice :: String -> ([Maybe Char],…

Philogy
- 283
- 1
- 12
0
votes
1 answer
Non-exhaustive patterns in function. Creating rose tree Haskell
I'm trying to write a function that combines a list of rose trees with the their parent node being the highest values of the root nodes of the given rose trees. For example;
RosesToRose [Rose 1 [Rose 1 [], Rose 2 []], Rose 3 [], Rose 4 [Rose 10…

anon0987654321
- 35
- 5
0
votes
1 answer
Find a key by having its value using Data.Map in Haskell
I just started using Haskell some weeks ago and I lack of imagination to resolve a function in this situation.
So I am trying to find the predecessors of a vertex in a graph implemented in Haskell.
My graph :
-- | A directed graph
data Graph v =…

Velyyn S
- 89
- 6
0
votes
1 answer
Getting non-exhaustive pattern exception on method
I keep getting non-exhaustive pattern exception for the following method:
groups::[Int]->[[Int]]
groups ls=go ls [] [] where
go [] small big=small:big
go (x:xs) (y:ys) big | x==y = go xs (x:y:ys) big
|…

Bercovici Adrian
- 8,794
- 17
- 73
- 152
0
votes
1 answer
Haskell take first and seventh
I need to write a function in Haskell that given a list of at least 7 elements returns a tuple containing the first and seventh element.
e.g.
Prelude> take1and7 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
(1, 7)
I've tried this
take1and7 :: [a] -> (a,…

Huddlespith
- 123
- 1
- 2
- 8
0
votes
2 answers
ML : match non-exhaustive
I want to make function named headcol that works like:
headcol[[1,2],[3,4]] = [1,3];
So i made function like this:
fun headcol [] = []
| headcol [x::xs',y::ys'] = [x,y]
but when I call it, I get a match nonexhaustive.

zion
- 25
- 4
0
votes
1 answer
How is it possible to get `Non-exhaustive patterns` exception when using `otherwise`
I'm trying to prove that the numbers of the form p_1 * ... * p_k + 1 are not all prime, and to do this, I have written this code
sieve :: [Integer] -> [Integer]
sieve (0:xs) = sieve xs
sieve (x:xs) = x : sieve (mark x xs)
where
mark :: Integer ->…

Our
- 986
- 12
- 22
0
votes
1 answer
Non-exhaustive pattern in function in Haskell
I have a class Evol and want an instance of distanceMatrix to be applied on a list of my type MolSeq. The function molseqDistMat works as desired, but I cant understand the error I get when trying to run distanceMatrix [Molseq]. I understand what…

Anton Fahlgren
- 37
- 6
0
votes
1 answer
haskell: negation normal form's function get "Non-exhaustive pattern" exception
-- | data type definition of WFF: well formed formula
data Wff = Var String
| Not Wff
| And Wff Wff
| Or Wff Wff
| Imply Wff Wff
-- | Negation norm form nnf function
-- precondition: φ is implication free
-- …

Johnny
- 5
- 2
0
votes
1 answer
Non-exhaustive patterns
Given I have the following code:
data Note = C | Db | D | Eb | E | F | Gb | G | Ab | A | Bb | B
deriving (Show, Eq, Ord, Enum)
next :: Note -> Note
next B = C
next n = succ n
previous :: Note -> Note
previous C = B
previous n = pred…

prog keys
- 687
- 1
- 5
- 14
0
votes
3 answers
Implementation of a program in which characters of a string repeated certain times in haskell
This is a question from my homework thus tips would be much likely appreciated.
I am learning Haskell this semester and my first assignment requires me to write a function that inputs 2 string (string1 and string2) and returns a string that is…

Ahmed Zaidi
- 15
- 2