Non exhaustive pattern in function noThirds

user3528269

So, my Problem is, that I have to write a program that filters all 3 * x (3,6,9...) elements from a list. My program looks like:

length'  :: [a] -> Int
length' = foldr (\_ -> (+1)) 0

help_ :: [a] -> [a] -> [a]
help_ (x:xs) [] = help_ (xs) [x]
help_ [] (x) = (x)
help_ (x:xs) (y)
    |((length' [xs]) ==0) = (y)
    |((length' [y]) `mod` 2 ==0) = help_ (xs) (y)
    |otherwise = help_ (xs) (y++[x])

noThirds :: [a] -> [a]
noThirds [x] = help_ [x] []

The compiler accepts this but gives the error "Non exhaustive pattern in function noThirds" when I enter "noThirds [1,2,3,4,5,6,7,8]" . I guess it's cause im missing a variety of "help_ .." but I don't get it. Im grateful for every help! Btw predefined list and arithmetic functions are not allowed.

Daniel Gratzer

It's because noThirds only has one pattern, [x] which only matches against a single element list. [x] is exactly equivalent to (x : []). What I think you meant was

noThirds :: [a] -> [a]
noThirda xs = help_ xs []

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Non exhaustive pattern in function in GHCi

From Dev

Non-exhaustive pattern in function-Haskell

From Dev

Why is this a non exhaustive search pattern?

From Dev

Non-exhaustive pattern match for Swift enum

From Dev

Non-exhaustive Pattern Match Warning with Tuple

From Dev

Instance Eq at Haskell -> Non-exhaustive pattern

From Dev

Non-exhaustive pattern matching in Haskell

From Dev

Haskell pattern matching - Non-exhaustive pattern - but why?

From Dev

Non-exhaustive patterns in my function

From Dev

"non-Exhaustive patterns in function listelem" haskell

From Dev

Non-exhaustive patterns in function trace'

From Dev

Haskell - Non-exhaustive patterns in function

From Dev

Intercalate function giving Non-exhaustive patterns

From Dev

Error: Non-exhaustive patterns in function Haskell

From Dev

Haskell: Non-exhaustive patterns in factorial function

From Dev

How to deal with false positive on non-exhaustive pattern matches?

From Dev

Warning that pattern guard is non-exhaustive even though it is

From Dev

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

From Dev

Haskell, Non-exhaustive patterns in function - way for checking this condition

From Dev

Non-exhaustive patterns in function - finding lower bound

From Dev

Haskell non-exhaustive patterns and converting function output

From Dev

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

From Dev

Non-exhaustive patterns in aux function for tying the knot

From Dev

Haskell, Non-exhaustive patterns in function - way for checking this condition

From Dev

Pattern match(es) are non-exhaustive even though I have specified the pattern

From Dev

Match non exhaustive in sml

From Dev

Avoid non-exhaustive pattern match when using para recursion-scheme

From Dev

ghc does not report non-exhaustive pattern matches when using the `no-code` flag

From Dev

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

Related Related

  1. 1

    Non exhaustive pattern in function in GHCi

  2. 2

    Non-exhaustive pattern in function-Haskell

  3. 3

    Why is this a non exhaustive search pattern?

  4. 4

    Non-exhaustive pattern match for Swift enum

  5. 5

    Non-exhaustive Pattern Match Warning with Tuple

  6. 6

    Instance Eq at Haskell -> Non-exhaustive pattern

  7. 7

    Non-exhaustive pattern matching in Haskell

  8. 8

    Haskell pattern matching - Non-exhaustive pattern - but why?

  9. 9

    Non-exhaustive patterns in my function

  10. 10

    "non-Exhaustive patterns in function listelem" haskell

  11. 11

    Non-exhaustive patterns in function trace'

  12. 12

    Haskell - Non-exhaustive patterns in function

  13. 13

    Intercalate function giving Non-exhaustive patterns

  14. 14

    Error: Non-exhaustive patterns in function Haskell

  15. 15

    Haskell: Non-exhaustive patterns in factorial function

  16. 16

    How to deal with false positive on non-exhaustive pattern matches?

  17. 17

    Warning that pattern guard is non-exhaustive even though it is

  18. 18

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

  19. 19

    Haskell, Non-exhaustive patterns in function - way for checking this condition

  20. 20

    Non-exhaustive patterns in function - finding lower bound

  21. 21

    Haskell non-exhaustive patterns and converting function output

  22. 22

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

  23. 23

    Non-exhaustive patterns in aux function for tying the knot

  24. 24

    Haskell, Non-exhaustive patterns in function - way for checking this condition

  25. 25

    Pattern match(es) are non-exhaustive even though I have specified the pattern

  26. 26

    Match non exhaustive in sml

  27. 27

    Avoid non-exhaustive pattern match when using para recursion-scheme

  28. 28

    ghc does not report non-exhaustive pattern matches when using the `no-code` flag

  29. 29

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

HotTag

Archive