Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.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
Algorithm “哈斯克尔”;“作为模式”;in算法_Algorithm_Haskell_Pattern Matching - Fatal编程技术网

Algorithm “哈斯克尔”;“作为模式”;in算法

Algorithm “哈斯克尔”;“作为模式”;in算法,algorithm,haskell,pattern-matching,Algorithm,Haskell,Pattern Matching,compress是一个删除列表元素连续重复项的函数 compress (x:ys@(y:_)) | x == y = compress ys | otherwise = x : compress ys compress ys = ys 现在,x:ys是否与(x:ys@(y:))中的y:模式相同?如果是,那么该函数如何正确执行?不,它们不一样。@符号用于为参数命名,并与@符号后的图案匹配 在您的示例中,ys是(y:)的同义词。把它写成(x:(ys@(y:))会让它更清楚x是

compress
是一个删除列表元素连续重复项的函数

compress (x:ys@(y:_))
    | x == y    = compress ys
    | otherwise = x : compress ys
compress ys = ys

现在,
x:ys
是否与
(x:ys@(y:))中的
y:
模式相同?如果是,那么该函数如何正确执行?

不,它们不一样。@符号用于为参数命名,并与@符号后的图案匹配

在您的示例中,
ys
(y:)
的同义词。把它写成
(x:(ys@(y:))
会让它更清楚
x
是列表的第一个元素,
y
是列表的第二个元素,
ys
是没有第一个元素的列表
x