Questions tagged [non-exhaustive-patterns]

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.

85 questions
1
vote
2 answers

How to fix "Non-exhaustive patterns in function"

I want pass a list as parameter to a function which multiply every element of this list by 3. I has to use recursion (I know how to do it) and map function (there is a problem). I'm trying passing a list as a parameter as I've seen in other posts…
Barburka
  • 407
  • 1
  • 7
  • 15
1
vote
1 answer

"Non-exhaustive patterns in function" error when appending value before function call

I'm not sure what I'm not handling. Suppose I have a function, that converts an integer to a string. Call it converter. Now, to convert position integer to string, I just call converter. To convert a negative integer to string, I append - to the…
SilentDev
  • 20,997
  • 28
  • 111
  • 214
1
vote
1 answer

How to implement a function to change array cells avoiding non-exhaustive pattern errors in haskell?

My goal is to write a function called walk, which switches the value of a labyrinth cell with its neighbour. For example calling walk 0 labyrinthA should move the T one cell to the left.Here i tried to change a value of a labyrinth cell in…
1
vote
0 answers

Non-exhaustive patterns error when defining foldr variant

I was asked to make a function that works like foldr but with non empty lists, that works like this: foldr1 f [x1,x2...xn] = f x1 (f x2...(f xn-1 xn)...). So I defined it like this: foldr1 f [x] = x foldr1 f (x:xs) = f x (foldr1 f xs) foldr1 f _ =…
1
vote
2 answers

How to deal with recursing through a list in Haskell (transpose operation)

While I understand that there may be transpose or ZipList functions in Haskell, I am trying to build my own transpose function that will take n lists of equal length m and transpose them into m lists of length n. So far I have the function nearly…
1
vote
2 answers

Non-exhaustive patterns, Haskell

I am trying to write the function tails, which converts a string into a list of strings in the following way: tails "abc" = ["abc", "bc", "c", ""] Here is my implementation: tails :: [Char] -> [[Char]] tails (x:xs) | length (x:xs) == 0 = [""] …
1
vote
1 answer

Match nonexhaustive im ML treemap function

Hello I am new to ML and am writing a treemap function for the following datatype : datatype tree = NIL | CONS of (tree * tree) | LEAF of int; This is my treemap function: fun treemap f = fn LEAF x => LEAF (f x) | CONS(y,z) => CONS…
1
vote
1 answer

Exhaustiveness check in typeclasses for promoted types

I have promoted type Nat = Suc Nat | Zero and I want to make a typeclass class C (a :: Nat) b. Is there a way to convince GHC that instance C Zero b and instance C (Seq x) b covers all cases and therefore I don't need to explicitly declare C as a…
fakedrake
  • 6,528
  • 8
  • 41
  • 64
1
vote
2 answers

Haskell List Comprehension Non-exhaustive pattern when calling more than one parameter

To start with I have created a Type StudentMark which is a tuple taking firstly a String and secondly an Int. type StudentMark = (String, Int) This is my capMarks function: capMarks :: [StudentMark] -> [StudentMark] capMarks [cMarks] = [(st, mk) |…
GarethAS
  • 331
  • 2
  • 12
1
vote
1 answer

How to detect the end of a list in Haskell?

I'm writting a recursive function that use specific formulas to calculate 2 lists. But I will simplify the function so you can understand the problem I'm having because the point here is to detect [] of the list. So I've the following…
Lord Rixuel
  • 1,173
  • 6
  • 24
  • 43
1
vote
1 answer

Haskell: Non-exhaustive pattern - Checking if list is ascending

I have no idea why my function doesn't work. I have gone through all the posts about non-exhaustive functions but my functions fulfills all possible options as far as I can see. ascending :: [Int] -> Bool ascending [] = error "Empty…
deadfire19
  • 329
  • 2
  • 16
1
vote
2 answers

Non-exhaustive patterns in function haskell

I think I am missing the case where there's a one element list but I can't find a way to write it can someone help me? getBoard :: [String] -> [String] getBoard (h:t) | isLOL h = h: getBoard (t) | otherwise = [] isLOL :: String ->…
45Yoda
  • 31
  • 6
1
vote
1 answer

Haskell Non-Exhaustion

I was wondering if anyone could help me identify the part of the haskell code that would be non-exhaustive? I can't see how the base case isn't met at the end of the list. thanks a lot Jonny type Rule = (Char, String) type Rules = [Rule] type…
FoxGlove
  • 81
  • 4
1
vote
0 answers

Creating an infix operator

I've run into a little problem i can't seem to solve, been at it for a few hours now to no avail. I've defined a datatype, Hand. data Hand = Empty | Add Card Hand deriving (Eq, Show) And another type i'm using: data Card = Card { rank ::…
Rewbert
  • 347
  • 1
  • 3
  • 11
0
votes
1 answer

Haskell - Non-exhaustive patterns in case

I have got the following code: F (S core ps) = FAll core [] ps where FAll core acc ((name, (pc : pcs)) : ps) = case F' (pc : pcs) (readC pc core) core of Nothing -> if (length pcs) /= 0 then FAll…
user1054204