[Haskell-cafe] turning an imperative loop to Haskell

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Sep 6 10:14:23 EDT 2007


On 06/09/07, Axel Gerstenberger <axel.gerstenberger at gmx.de> wrote:
> Thanks to all of you. The suggestions work like a charm. Very nice.
>
> I still need to digest the advices, but have already one further
> question: How would I compute the new value based on the 2 (or even
> more) last values instead of only the last one?
>
> [ 2, 3 , f 3 2, f((f 3 2) 3), f ( f((f 3 2) 3)  f 3 2)), ...]

foo = 2 : 3 : zipWith f (drop 1 foo) foo

There's also zipWith3 etc. for functions with more arguments.

-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862


More information about the Haskell-Cafe mailing list