[Haskell-cafe] Simple list processing
Don Stewart
dons at galois.com
Wed Jun 11 14:25:17 EDT 2008
andrewcoppin:
> OK, so this is a fairly basic question about list processing.
>
> Several times now, I have found myself wanting to process a list to
> produce a new list. However, the way later elements are processed
> depends on what the earlier elements are - in other words, this isn't a
> simple "map".
>
> What is the best way to handle this?
>
> According to the theory, anything that consumes a list and produces a
> value is some kind of fold. [Assuming it traverses the list in a
> sensible order!] So it looks like you could implement this as a fold.
> But should that be a LEFT-fold or a RIGHT-fold? (I always get confused
> between the two!)
>
Sounds like a mapAccum, a combination of map and fold,
http://haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html#v%3AmapAccumL
If you gave a concrete example it would be easier to diagnose.
-- Don
More information about the Haskell-Cafe
mailing list