
24 Nov
2006
24 Nov
'06
6:07 a.m.
Hello, i'd like to write a function that given a list like [1,2,3,4...] returns a list of couple where the first element is the corresponding element of the string, and the second is the sum of the previous elements. An example: input: [1,2,3,4] output: [(1,0)(2,1)(3,3)(4,6)] The problem is that I'd like to use foldl and a solution like: buildCouples = snd . foldl op (0,[]) where op (v,xs) x = (v+x,xs++[(x,v)]) is not good since the operator ++ let the function take 2*n time and not n. Can anyone help me please? Clare -- View this message in context: http://www.nabble.com/Foldl-tf2698202.html#a7524410 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.