Proposal: Export cycleN from Data.Sequence

David Feuer david.feuer at gmail.com
Tue Apr 26 03:50:36 UTC 2016


It's been quite a while, and I've had a single +1 on this with very
little comment. Does anyone else have an opinion? Is anyone opposed?
Does anyone think `cycleN n` should produce a *result* of length `n`
instead of cycling `n` times? I seek advice and consent of anyone who
cares.

On Wed, Mar 11, 2015 at 11:14 AM, David Feuer <david.feuer at gmail.com> wrote:
> Yesterday I rewrote `*>` for Data.Sequence (again), using an internal function
>
> cycleN :: Int -> Seq a -> Seq a
>
> The name of the function is based on that of Data.Sequence.iterateN.
> cycleN takes a sequence and cycles it as many times as requested:
>
> cycleN 0 $ fromList [1,2] = []
> cycleN 5 $ fromList [1,2] = [1,2,1,2,1,2,1,2,1,2]
>
> The function is written to maximize sharing in the result sequence and
> to minimize construction time. Specifically, cycleN n xs should take
> something like O(|xs| + log n) space (of which all but O(log |xs| +
> log n) is shared with the structure of xs) and O(log |xs| + log n)
> time.
>
> With current (on GitHub) Data.Sequence exports, the only way to get
> this functionality with these time and space bounds is to combine
> replicate with *> :
>
> cycleN n xs = replicate n () *> xs
>
> This strikes me as a bit unpleasant.
>
> David


More information about the Libraries mailing list