Questions tagged [non-exhaustive-patterns]
73 questions
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…
![](../../users/profiles/4400821.webp)
overpro
- 29
- 6
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:…
![](../../users/profiles/4400821.webp)
overpro
- 29
- 6
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)…
![](../../users/profiles/1536010.webp)
skills
- 285
- 3
- 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)…
![](../../users/profiles/3124100.webp)
Bora
- 1,139
- 13
- 17
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
…
![](../../users/profiles/1683923.webp)
Deepali Semwal
- 99
- 2
- 8
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…
![](../../users/profiles/1110224.webp)
BradStevenson
- 1,874
- 6
- 26
- 40
-1
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 ::…
![](../../users/profiles/11094853.webp)
Alex
- 277
- 1
- 2
- 12
-1
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…
![](../../users/profiles/12097918.webp)
anon0987654321
- 29
- 4
-1
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 ->…
![](../../users/profiles/6708910.webp)
Our
- 691
- 9
- 19
-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
…
![](../../users/profiles/9924411.webp)
obla
- 93
- 1
- 7
-1
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…
![](../../users/profiles/949432.webp)
prog keys
- 675
- 1
- 5
- 13
-2
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 $…
![](../../users/profiles/10581778.webp)
nEYncI
- 3
- 2
-2
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…
![](../../users/profiles/4317506.webp)
Spencer Josephs
- 19
- 1
- 5