Semigroup repeat (base package)

Hi, I am sending this question here since base ships with ghc, let me know if this is not the right forum for this. I could not find a function that repeats a value using a semigroup append. I am looking for something like this: srepeat :: Semigroup a => a -> a srepeat x = xs where xs = x <> xs Is it already available somewhere? Does it make sense to add it to Data.Semigroup? Thanks, Harendra

Hi,
On Sun, Sep 10, 2017 at 9:24 AM, Harendra Kumar
I could not find a function that repeats a value using a semigroup append. I am looking for something like this:
srepeat :: Semigroup a => a -> a srepeat x = xs where xs = x <> xs
Is it already available somewhere? Does it make sense to add it to Data.Semigroup?
What you seem to be searching for looks more like what we know as `cycle :: [a] -> [a]`, and in fact there is its generalisation at http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Semigroup.html#v:... hth

Indeed it is cycle1, sorry to have missed it. It will be easier to spot it
if it close to the stimes* functions in the beginning of the docs. It is
placed too far down below even after Monoid re-exports.
-harendra
On 10 September 2017 at 14:09, Herbert Valerio Riedel
Hi,
On Sun, Sep 10, 2017 at 9:24 AM, Harendra Kumar
wrote: I could not find a function that repeats a value using a semigroup append. I am looking for something like this:
srepeat :: Semigroup a => a -> a srepeat x = xs where xs = x <> xs
Is it already available somewhere? Does it make sense to add it to Data.Semigroup?
What you seem to be searching for looks more like what we know as `cycle :: [a] -> [a]`, and in fact there is its generalisation at
http://hackage.haskell.org/package/base-4.10.0.0/docs/ Data-Semigroup.html#v:cycle1
hth

Am Sonntag, den 10.09.2017, 10:39 +0200 schrieb Herbert Valerio Riedel:
What you seem to be searching for looks more like what we know as `cycle :: [a] -> [a]`, and in fact there is its generalisation at
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Semigroup.html#v:...
Why is this function called cycle1, not cycle? What does the “1” stand for? All the best, Wolfgang

On 11 September 2017 at 02:46, Wolfgang Jeltsch
Am Sonntag, den 10.09.2017, 10:39 +0200 schrieb Herbert Valerio Riedel:
What you seem to be searching for looks more like what we know as `cycle :: [a] -> [a]`, and in fact there is its generalisation at
http://hackage.haskell.org/package/base-4.10.0.0/docs/ Data-Semigroup.html#v:cycle1
Why is this function called cycle1, not cycle? What does the “1” stand for?
I guess this is not named "cycle" to avoid conflict with "Data.List.cycle". I was also wondering why it is "cycle1" instead of, say "scycle". It can be thought of as cycling just one value instead of cycling a list in case of "Data.List.cycle". I Just made up this explanation, original writers would know better. I would prefer "scycle" which is consistent with other functions in this package like "stimes", cycle1 sounds a bit random at first look. -harendra

Am Montag, den 11.09.2017, 06:55 +0530 schrieb Harendra Kumar:
On 11 September 2017 at 02:46, Wolfgang Jeltsch wrote:
Am Sonntag, den 10.09.2017, 10:39 +0200 schrieb Herbert Valerio Riedel:
What you seem to be searching for looks more like what we know as `cycle :: [a] -> [a]`, and in fact there is its generalisation at
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Semigroup.html#v:...
Why is this function called cycle1, not cycle? What does the “1” stand for?
I guess this is not named "cycle" to avoid conflict with "Data.List.cycle".
Why? We have qualified imports. It seems very wrong to add single characters to identifiers to denote name spaces.
I was also wondering why it is "cycle1" instead of, say "scycle". It can be thought of as cycling just one value instead of cycling a list in case of "Data.List.cycle".
Also Data.List.cycle cycles only one value. It is just that this single value happens to be a list. If you specialize cycle1 to the list monoid, you get exactly Data.List.cycle. All the best, Wolfgang

It's the same convention as with other Semigroup-like functions, such as
`foldl1`, `scanl1`, etc.
Doesn't really makes sense to distinguish between `cycle` and `cycle1` in
this case, but that's just bike shedding.
Also, at some point in the future, `cycle` can go in `Data.OldList` and be
replaced by `cycle1`, renamed accordingly.
On Mon, Sep 11, 2017 at 10:12 PM, Wolfgang Jeltsch wrote: Am Montag, den 11.09.2017, 06:55 +0530 schrieb Harendra Kumar: On 11 September 2017 at 02:46, Wolfgang Jeltsch wrote: Am Sonntag, den 10.09.2017, 10:39 +0200 schrieb Herbert Valerio
Riedel: What you seem to be searching for looks more like what we know as
`cycle :: [a] -> [a]`, and in fact there is its generalisation at http://hackage.haskell.org/package/base-4.10.0.0/docs/
Data-Semigroup.html#v:cycle1 Why is this function called cycle1, not cycle? What does the “1”
stand for? I guess this is not named "cycle" to avoid conflict with
"Data.List.cycle". Why? We have qualified imports. It seems very wrong to add single
characters to identifiers to denote name spaces. I was also wondering why it is "cycle1" instead of, say "scycle". It
can be thought of as cycling just one value instead of cycling a list
in case of "Data.List.cycle". Also Data.List.cycle cycles only one value. It is just that this single
value happens to be a list. If you specialize cycle1 to the list monoid,
you get exactly Data.List.cycle. All the best,
Wolfgang
_______________________________________________
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

No. Functions like foldl1 are named such because they start building a value with the first (“1”) value of a list and consequently do not work with empty lists. They have counterparts without the “1” in their names, which receive the initial value as an extra argument. Things are completely different with cycle1, which does not even take a list. All the best, Wolfgang Am Dienstag, den 12.09.2017, 09:19 +0200 schrieb Sebastian Graf:
It's the same convention as with other Semigroup-like functions, such as `foldl1`, `scanl1`, etc. Doesn't really makes sense to distinguish between `cycle` and `cycle1` in this case, but that's just bike shedding.
Also, at some point in the future, `cycle` can go in `Data.OldList` and be replaced by `cycle1`, renamed accordingly.
On Mon, Sep 11, 2017 at 10:12 PM, Wolfgang Jeltsch h.info> wrote:
Am Montag, den 11.09.2017, 06:55 +0530 schrieb Harendra Kumar:
On 11 September 2017 at 02:46, Wolfgang Jeltsch wrote:
Am Sonntag, den 10.09.2017, 10:39 +0200 schrieb Herbert Valerio Riedel:
What you seem to be searching for looks more like what we know as `cycle :: [a] -> [a]`, and in fact there is its generalisation at
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Sem igroup.html#v:cycle1
Why is this function called cycle1, not cycle? What does the “1” stand for?
I guess this is not named "cycle" to avoid conflict with "Data.List.cycle".
Why? We have qualified imports. It seems very wrong to add single characters to identifiers to denote name spaces.
I was also wondering why it is "cycle1" instead of, say "scycle". It can be thought of as cycling just one value instead of cycling a list in case of "Data.List.cycle".
Also Data.List.cycle cycles only one value. It is just that this single value happens to be a list. If you specialize cycle1 to the list monoid, you get exactly Data.List.cycle.
All the best, Wolfgang _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (4)
-
Harendra Kumar
-
Herbert Valerio Riedel
-
Sebastian Graf
-
Wolfgang Jeltsch