[Haskell-cafe] Sequence differences

michael rice nowgate at yahoo.com
Fri Apr 10 01:49:14 EDT 2009

I have a Scheme function that calculates sequence differences, i.e., it returns a sequence that is the difference between the 2nd and the 1st element, the 3rd and the 2nd, the 4th and the 3rd, etc.

(define s
  (lambda (f l)
    (cond ((null? (cdr l)) '())
          (else (cons (f (cadr l) (car l))
                      (s f (cdr l)))))))


(s - '(0,1,3,6,10,15,21,28)) => (1,2,3,4,5,6,7)

I'm thinking the same function in Haskell would be something like

s :: 
s f [] = []
s f [x] = [x] 
s f l = [ a f b | (a,b) <- zip (init l) (tail l)]

but can't figure out what the function typing would be.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090409/5bac288b/attachment.htm

More information about the Haskell-Cafe mailing list