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/2/python/302.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
Parsing 防护上的分析错误_Parsing_Sorting_Haskell_Merge - Fatal编程技术网

Parsing 防护上的分析错误

Parsing 防护上的分析错误,parsing,sorting,haskell,merge,Parsing,Sorting,Haskell,Merge,我正在实现merge sort的merge子例程。我在编译时收到以下错误消息:输入解析错误| merge :: [Int] -> [Int] -> [Int] merge xs ys = go xs ys [] where go xs ys zs = |null ys = zs ++ xs |null xs = zs ++ ys

我正在实现merge sort的merge子例程。我在编译时收到以下错误消息:输入解析错误|

merge :: [Int] -> [Int] -> [Int]
merge xs ys = go xs ys []
    where go xs ys zs =
            |null ys              = zs ++ xs                     
            |null xs              = zs ++ ys                        
            |(head xs) <= head ys = go (tail xs) ys (head xs : zs)  
            |otherwise            = go xs (tail ys) (head ys : zs)
merge::[Int]->[Int]->[Int]
合并xs ys=go xs ys[]
xs ys zs去哪里=
|空ys=zs++xs
|空xs=zs++ys

|(head xs)您可以通过删除
go xs ys zs
之后的
=
来修复语法错误-当定义带有保护的内容时,
=
只出现在每个保护之后,就像您已经有的那样

除此之外,如果您更多地使用模式匹配,您的代码将更干净。您可以使用模式
[]
来识别空列表和
(x:xs)
来识别非空列表,并将头和尾绑定到名称
x
xs
,等等,而不是先检查列表是否为
null
,然后再检查
头和

merge :: [Int] -> [Int] -> [Int]
merge xs ys = go xs ys []
    where go xs [] zs          = zs ++ xs
          go [] ys zs          = zs ++ ys
          go (x:xs) (y:ys) zs
              | x <= y         = go xs (y:ys) (x:zs)
              | otherwise      = go (x:xs) ys (y:zs)
merge::[Int]->[Int]->[Int]
合并xs ys=go xs ys[]
其中go xs[]zs=zs++xs
go[]ys zs=zs++ys
go(x:xs)(y:ys)zs

|x您在
go xs ys zs
之后有一个额外的
=
——当定义带有防护装置的内容时,
=
只在每个防护装置之后出现,就像您已经有的那样。