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
0
votes
2 answers

Haskell - "Non-exhaustive patterns" error with a function using list

I'm trying to make a function in haskell to know if all the elements in a list of list have the same length. (I've search answers in previous posts but none of them works). sameLength :: [[t]] -> String sameLength [] = "Empty list" sameLength…
Prygan
  • 95
  • 1
  • 9
0
votes
1 answer

Non-exhaustive patterns in function trace'

trace :: String -> Float -> Colour -> [ColouredLine] trace (c:cs) angle colour = trace' (c:cs) angle colour (0.0,0.0) where trace' "" angle colour intvertex = [] trace' (c:cs) angle colour intvertex | c == 'R' = trace' cs…
overpro
  • 49
  • 8
0
votes
1 answer

Non-exhaustive on Haskell recursion

sumAllDigits :: [ Int ] -> Int sumAllDigits (x:xs) |(x:xs) == [] = 0 |x >= 10 = sumDigits x + sumAllDigits xs |x< 10 = x + sumAllDigits xs REPORT: *Recursion> sumAllDigits [22,33] *** Exception:…
overpro
  • 49
  • 8
0
votes
1 answer

Non-exhaustive pattern in function declaration

I'm having difficulties implementing the following function: type Tabuleiro = [String] type Comandos = String type Comando = String type Coordenadas = String novaCoord :: Tabuleiro -> Comandos -> Coordenadas -> Coordenadas novaCoord l (cmd:xs)…
skills
  • 315
  • 5
  • 17
0
votes
1 answer

Non-exhaustive patterns in function error

In haskel, I got an error and somehow I couldn't find the right solution. There is the error i get and my code: My code: data MyTree = Leaf Float | Tree String MyTree MyTree deriving (Show, Eq, Ord) asgCodeRec1 [] _ = [] asgCodeRec1 (a:b:c) (y:ys)…
Bora
  • 1,402
  • 16
  • 19
0
votes
1 answer

Exception : Pattern Matching failure Haskell

I am trying to implement Standard words function of Haskell. I am using State Monad to solve the problem. My Code is : type WorS = ([String],String,String) words' :: State WorS [String] words' = do (lwords, words, x:xs) <- get …
0
votes
2 answers

Haskell: Non-exhaustive patterns in function (simple functions)

I am confused as to why the 1st and 3rd versions of this functions give this error whereas the second definition works fine. -- head and tail third :: [a] -> a third [a] = head (tail (tail[a])) -- Pattern matching third2 :: [a] -> a third2…
BradStevenson
  • 1,974
  • 7
  • 26
  • 40
-1
votes
1 answer

Non-exhaustive patterns in function Exception in haskell

I have this code: import Data.Char foo :: String -> String foo (x:xs) = if (digitToInt(x)) == 0 then foo xs else if (digitToInt(x)) /= 0 then replicate (digitToInt(x)) (head $…
nEYncI
  • 3
  • 2
-1
votes
3 answers

Fatal error: exception Match_failure("main.ml", 8, 15)

Here is my code: type 'a tree = Empty | N of 'a * 'a tree * 'a tree let absolute x = if x > 0 then x else -x let rec node = function | N(_, Empty, Empty) -> 1 | N(_, g, d) -> 1 + node g + node d let rec balanced = function …
obla
  • 123
  • 2
  • 7
-1
votes
1 answer

Keep getting matching error in haskell when testing function

this is the function toRevDigits :: Integer -> [Integer] toRevDigits 0 = [] toRevDigits x | x<0 = [] | otherwise = lastDigit x:(toRevDigits (dropLastDigit x)) this is the test testRevDigits :: (Integer, [Integer]) -> Bool testRevDigits…
1 2 3 4 5
6