Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;“非穷举模式”;在Haskell函数中_Haskell_Arguments_Pattern Matching - Fatal编程技术网

&引用;“非穷举模式”;在Haskell函数中

&引用;“非穷举模式”;在Haskell函数中,haskell,arguments,pattern-matching,Haskell,Arguments,Pattern Matching,在以下Haskell函数中: allTransformations :: String -> String -> [Transformation] allTransformations "" "" = [] allTransformations a "" = [map (\a -> Delete a) a] allTransformations "" b = [map (\b -> Insert b) b] allTransformations (x:xs) (y:ys)

在以下Haskell函数中:

allTransformations :: String -> String -> [Transformation]
allTransformations "" "" = []
allTransformations a "" = [map (\a -> Delete a) a]
allTransformations "" b = [map (\b -> Insert b) b]
allTransformations (x:xs) (y:ys)
    | x == y = map (\t -> (Copy x) : t) rest
    | (length xs) < (length ys) = (map (\t -> (Insert y) : t) rest) ++ (map (\t -> (Change x y) : t) rest)
    | (length xs) > (length ys) = (map (\t -> (Delete x) : t) rest) ++ (map (\t -> (Change x y) : t) rest)
    where rest = allTransformations xs ys
allTransformations::String->String->[转换]
所有转换“”=[]
所有转换a”“=[映射(\a->删除a)a]
allTransformations“”b=[映射(\b->插入b)b]
所有变换(x:xs)(y:ys)
|x==y=map(\t->(复制x):t)rest
|(长度xs)<(长度ys)=(映射(\t->(插入y):t)rest)+(映射(\t->(更改x y):t)rest)
|(长度xs)>(长度ys)=(映射(+\t->(删除x):t)rest)+(映射(+\t->(更改x y):t)rest)
其中rest=allTransformations xs ys
运行
allTransformations“abc”“bca”
时,出现错误“函数allTransformations中的非穷举模式”。问题在哪里

我讨论了四种情况:两个参数都是空字符串,第二个参数是空的,第一个不是空的,第一个参数是空的,第二个不是空的,两个参数都不是空的


这是所有可能的案例,对吗?

您实际上已经涵盖了六个案例,因为您提到的第四个案例有三个不同的守卫:

  • 两个都是空的
  • A是空的
  • B是空的
  • 两个元素都不是空的,并且第一个元素是相同的
  • 两者都不是空的,A更长
  • 两者都不是空的,B更长
您缺少:

  • 两个元素都不是空的,第一个元素不相等,并且它们的长度相同

最后一个案例正是“abc”和“bca”的案例,您实际上已经涵盖了六个案例,因为您提到的第四个案例有三个不同的保护措施:

  • 两个都是空的
  • A是空的
  • B是空的
  • 两个元素都不是空的,并且第一个元素是相同的
  • 两者都不是空的,A更长
  • 两者都不是空的,B更长
您缺少:

  • 两个元素都不是空的,第一个元素不相等,并且它们的长度相同

最后一个例子正是“abc”和“bca”的例子哦,是的,那太傻了。我不认为这四个“外部”案例中的最后一个取决于各种情况。哦,是的,那太愚蠢了。我不认为四个“外部”案例中的最后一个本身依赖于各种情况。拇指规则:如果一个保护块没有以<代码>结尾,否则,那么在保护之前的模式可能不会捕获所有的情况,因此在检查穷尽性时可以忽略。(另外,启用警告,这样您就不必仅在运行时捕获这些错误)拇指规则:如果保护块未以
结束,否则
,则保护之前的模式可能不会捕获所有情况,因此在检查穷尽性时可以忽略它。(另外,启用“警告”,这样您就不必仅在运行时捕获这些错误)