Reputation: 31
My function paralellenCheck
throws an exception everytime I call it complaining about Non-exhaustive patterns
paralellenCheck
is defined as follows:
paralellenCheck :: (Eq a, Num a ) => [a] -> [a] -> Bool
paralellenCheck [] [] = True
paralellenCheck [_] [] = True
paralellenCheck [] [_] = True
paralellenCheck (x:xs) (y:ys)
| intervall `elem` [0,5,7,12] = False
| not $ paralellenCheck (x:xs) ys = False
| not $ paralellenCheck xs (y:ys) = False
| otherwise = True
where intervall = abs (x - y)
running the function in GHCI with -Wall applied just returns
<interactive>:10:1:
Warning: Defaulting the following constraint(s) to type `Integer'
(Eq a0)
arising from a use of `paralellenCheck' at <interactive>:10:1-15
(Num a0)
arising from a use of `paralellenCheck' at <interactive>:10:1-15
In the expression: paralellenCheck [] [2, 3, 4, 5]
In an equation for `it': it = paralellenCheck [] [2, 3, 4, ....]
<interactive>:10:1:
Warning: Defaulting the following constraint(s) to type `Integer'
(Eq a0)
arising from a use of `paralellenCheck' at <interactive>:10:1-15
(Num a0)
arising from a use of `paralellenCheck' at <interactive>:10:1-15
In the expression: paralellenCheck [] [2, 3, 4, 5]
In an equation for `it': it = paralellenCheck [] [2, 3, 4, ....]
*** Exception: haskelltest.hs:(6,1)-(14,31): Non-exhaustive patterns in function paralellenCheck
I am rather new to haskell and rather confused. I thought the pattern-matching with [_] []
and [] [_]
should resolve this issue.
Upvotes: 1
Views: 125
Reputation: 2528
[_]
in a pattern means "any list of exactly one element". You seem to have intended "any list at all". Right now, [] (a:b:[])
, for example, is not matched. Use _
for any list.
Upvotes: 7