计算给定整数列表中连续元素之间的差异

时间:2016-06-25 20:17:29

标签: haskell

我正在使用zipWith。我得到了正确的结果,但标志不正确。我如何解决它?我哪里错了?

diff :: [Int] -> [Int]
diff [] = []
diff x = zipWith (-) (tail x) x

结果:

diff  [4,2,7,3,6,5]
[-2,5,-4,3,-1]

我想:

[2,-5,4,-3,1]

1 个答案:

答案 0 :(得分:4)

如你所知,现在你正在计算Range("A1").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$E$8").AutoFilter Field:=1, Criteria1:=Range("H1") 。如果您将参数的顺序交换为[2-4,7-2,3-7,6-3,5-6],则会将其更正为zipWith (-) x (tail x)