[Haskell-cafe] Running Total or Incremental Sum as a higher order
type ?
Crypt Master
cryptmaster at hotmail.com
Sat Jul 3 05:29:25 EDT 2004
Hi
I was attempting to get a running a total of a list i.e
for [1,2,3]
the result should be
[1,3,6] -- [1, 1+2, 2+3]
I build this function:
incrementalSum [] x = []
incrementalSum (x:xs) runningTotal = currentSum : incrementalSum xs
currentSum
where
currentSum =
runningTotal + x
I was trying to see how I could higher order functions for this but came up
empty. Surely this is a pattern which has been abstracted ? I feel I have
missed the obvious here.
Thanks,
S
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
More information about the Haskell-Cafe
mailing list