简体   繁体   English

Haskell简单程序模式匹配错误

[英]Haskell Simple program pattern matching error

If given list of numbers [3,1,4,6,2] -> I increase every odd element by 1 and decrease every even element by 1 I should get [4,0,5,5,3] 如果给定数字列表[3,1,4,6,2]->我将每个奇数元素加1,并将每个偶数元素减1,我应该得到[4,0,5,5,3]

my code is 我的代码是

change [] = []
change (x:y:xs) = (x+1)(y-1):change xs

I write function change with a base case where if list is null it returns null list and then it recursively increases every odd elment by 1 and decrease all even indexed elements by 1 and pushes them back to the list 我用基本情况编写函数更改,如果list为null,则返回null list,然后递归地将每个奇数元素加1,并将所有偶数索引元素减1,然后将它们推回到列表中

However I get a pattern matching error. 但是我收到模式匹配错误。 What have I done wrong? 我做错了什么? And how can this be fixed? 以及如何解决?

您缺少带有一个IntList的情况:

change [x]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM