"函数listelem中的非穷举模式"haskell

Sta*_*ebo 5 haskell

嗨,我对哈斯克尔很新.我正在尝试编写一个代码,允许我输入一个坐标系列表(CS1)(即一个坐标列表列表)和一个不允许的所有坐标列表(CL).该函数的目的是丢弃CS1中包含CL中至少1个这些坐标的所有坐标系,最后得到CS1中较小的坐标系子集(CS2).(令人困惑?对不起)

我认为我非常接近破解坚果(虽然我真的不知道,因为我正处于线索错误阶段),但是当我运行listelem2时,我有一个非穷举的问题,它会在侦听中抱怨.任何人都能看到我错过的东西吗?谢谢你提供的所有帮助!:d

listelem0 :: (Eq a) => [a] -> a -> [a]
listelem0 [] y = []
listelem0 (x:xs) y 
            | x == y = []
            | x /= y = [x] ++ listelem0 xs y

listelem :: (Eq a) => [a] -> a -> [a]
listelem (x:xs) y
      | length (listelem0 (x:xs) y) < length (x:xs) = []
      | otherwise = listelem0 (x:xs) y

listelem1 :: (Eq a) => [[a]] -> a -> [[a]]
listelem1 [] y = []
listelem1 (x:xs) y = [listelem x y] ++ listelem1 xs y  

listelem2 :: (Eq a) => [[a]] -> [a] -> [[a]]
listelem2 [] [] = [[]]
listelem2 (x:xs) [] = (x:xs)
listelem2 (x:xs) (y:ys) = listelem2 (listelem1 (x:xs) y) ys
Run Code Online (Sandbox Code Playgroud)

ami*_*dfv 13

Emil是对的,你错过了这两种模式,但是你可以自己找到那些缺失的模式:

如果你运行ghci -Wall yourFile.hs(或ghci -fwarn-incomplete-patterns yourFile.hs),你会看到所有不完整的模式:

[1 of 1] Compiling Main             ( /tmp/ls.hs, interpreted )

/tmp/ls.hs:2:1:
    Warning: Pattern match(es) are non-exhaustive
             In an equation for `listelem0': Patterns not matched: (_ : _) _

/tmp/ls.hs:8:1:
    Warning: Pattern match(es) are non-exhaustive
             In an equation for `listelem': Patterns not matched: [] _

/tmp/ls.hs:17:1:
    Warning: Pattern match(es) are non-exhaustive
             In an equation for `listelem2': Patterns not matched: [] (_ : _)
Ok, modules loaded: Main.
Run Code Online (Sandbox Code Playgroud)

让我们以最后一个为例:In an equation for listelem2': Patterns not matched: [] (_ : _)- 这意味着它听起来像:模式listelem2 [] (something:somethingElse)永远不匹配.


Emi*_*röm 4

您没有这些调用的模式:

  • listelem [] y
  • listelem2 [] (y:ys)