Proposal: Export cycleN from Data.Sequence

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

+1, `cycleN` is Data.Sequence's corollary of `cycle` in Data.List
On Wed, Mar 11, 2015 at 8:14 AM, David Feuer
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 _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Love in Jesus Christ, John Alfred Nathanael Chee http://www.biblegateway.com/ http://web.cecs.pdx.edu/~chee/

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
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

Hi, I consent, and have no advice to offer :-) Greetings, Joachim Am Montag, den 25.04.2016, 23:50 -0400 schrieb David Feuer:
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
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
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org
participants (3)
-
David Feuer
-
Joachim Breitner
-
John Alfred Nathanael Chee