Handling sequential data
The standard list,[]
, is the most used data structure for sequential data. It has reasonable performance, but when processing multiple small values, say Chars
, the overhead of a linked list might be too much. Often, the convenient nature of []
is convincing enough.
The wide range of list functions in Data.List
are hand-optimized and many are subject to fusion. List fusion, as it is currently implemented using the foldr/build fusion transformation, is subtly different from stream fusion employed in ByteString and Text (concatMap
is a bit problematic with traditional stream fusion). Still, the end result is pretty much the same; in a long pipeline of list functions, intermediate lists will usually not be constructed.
Say we want a pipeline that first increases every element by one, calculates intermediate sums of all elements up to current element, and finally sums all elements. From the previous chapter, we have learned to write optimally strict recursive functions...