想再询问您一道Haskell的题目,找下面程序的8个error是什么,非常感谢!
定义mergesort的一个函数,一共有8个error。mergeSort::([a]->[a]->[a])->[a]->[a]->[a]mergeSortmergexs...
定义merge sort的一个函数,一共有8个error。
mergeSort :: ([a] -> [a] -> [a]) -> [a] -> [a] -> [a]
mergeSort merge xs
| length xs <= 2 =xs
| else
== merge (mergeSort merge first)
(mergeSort merge second)
where first = take half ys
second = drop half xs
halve = (length xs) div 2 展开
mergeSort :: ([a] -> [a] -> [a]) -> [a] -> [a] -> [a]
mergeSort merge xs
| length xs <= 2 =xs
| else
== merge (mergeSort merge first)
(mergeSort merge second)
where first = take half ys
second = drop half xs
halve = (length xs) div 2 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2个回答
展开全部
其实你guard的用法没有问题, 只是有点语法错误
mergeSort merge xs
| length xs <= 2 =xs
| otherwise = merge (mergeSort merge first) (mergeSort merge second)
where first = take half ys
second = drop half xs
halve = (length xs) div 2
应该用otherwise 而不是else
mergeSort merge xs
| length xs <= 2 =xs
| otherwise = merge (mergeSort merge first) (mergeSort merge second)
where first = take half ys
second = drop half xs
halve = (length xs) div 2
应该用otherwise 而不是else
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是正确代码
mergeSort :: ([a] -> [a] -> [a]) -> [a] -> [a]
mergeSort merge xs =
if length xs <= 2 then xs
else merge (mergeSort merge first)
(mergeSort merge second)
where
first = take halve xs
second = drop halve xs
halve = (length xs) `div` 2
mergeSort :: ([a] -> [a] -> [a]) -> [a] -> [a]
mergeSort merge xs =
if length xs <= 2 then xs
else merge (mergeSort merge first)
(mergeSort merge second)
where
first = take halve xs
second = drop halve xs
halve = (length xs) `div` 2
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询