Questions tagged [non-exhaustive-patterns]
73 questions
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
0
votes
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…
![](../../users/profiles/10998152.webp)
logn
- 51
- 2
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…
![](../../users/profiles/14870932.webp)
Smite
- 57
- 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],…
![](../../users/profiles/5780363.webp)
MrClottom
- 266
- 1
- 12
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 =…
![](../../users/profiles/12151860.webp)
Velyyn S
- 87
- 5
0
votes
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…
![](../../users/profiles/8196562.webp)
Barburka
- 339
- 1
- 3
- 12
0
votes
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…
![](../../users/profiles/10592398.webp)
that-cs-dude
- 13
- 2
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
|…
![](../../users/profiles/1913744.webp)
Bercovici Adrian
- 6,415
- 9
- 47
- 90
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,…
![](../../users/profiles/5699038.webp)
Huddlespith
- 93
- 2
- 8
0
votes
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 _ =…
![](../../users/profiles/10609356.webp)
Jaime Fernández
- 109
- 4
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.
![](../../users/profiles/10536563.webp)
zion
- 25
- 4
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…
![](../../users/profiles/4224979.webp)
Anton Fahlgren
- 17
- 5
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
-- …
![](../../users/profiles/5364621.webp)
Johnny
- 5
- 1
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…
![](../../users/profiles/4914505.webp)
Ahmed Zaidi
- 15
- 2
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…
![](../../users/profiles/4281300.webp)
Prygan
- 65
- 1
- 8