Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: Calculate differences of every pair of adjacent elements in a list

Tags:

list

haskell

I have a function (mergeall) that returns a float list. I want to calculate differences of every pair of adjacent elements in this list. For example:

[1.1,2.2,3.3,4.4,5.5,6.6]
do 1.1-2.2, 2.2-3.3,3.3-4.4...
return list of all difference

So, this should be pass into a list and return a list. The problems are:

  1. How can I use the list from "mergeall"?
  2. How can I do the algorithm above? Could somebody help me? Thanks!
like image 847
SPG Avatar asked Dec 07 '11 00:12

SPG


1 Answers

differences fs = zipWith (-) fs (tail fs)
like image 158
Lily Ballard Avatar answered Nov 15 '22 10:11

Lily Ballard