This patch contains several methods for Data.Sequence I've always thought were long missing:
- scans. This addition is almost trivial with the Traversable instance, but to match properly with the Data.List definitions (which change the length of the output string) requires only a single cons or snoc.
- replicate. I don't know why this hasn't been in Data.Sequence already, because with some care, it uses O(log n) memory and amortized time by sharing nodes internally, and that's pretty cool.
-
zip. This is the one I really wanted to see in Data.Sequence, and I tried out a number of approaches, most of which simply never could work. This implementation truncates the sequences to the same size and then zips from both left and right at once, aligning digits together and handling remainders appropriately. Look at the source for details. More importantly, though, my GHC benchmarks indicate this is oodles faster than the standard workaround -- converting to lists and back.
Louis Wasserman
wasserman.louis@gmail.com