-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Semigroup and Monoid instances for ZipList #100
Comments
Using Prelude Data.Align Data.Monoid Data.Coerce> coerce $ salign [1 :: Sum Int, 2, 3] [1] :: [Int]
[2,2,3] I thought That is a hint that there is no I will find it somewhat confusing that |
Is align the common term for what I'm trying to do? If so, then that invalidates my last reason for adding it to |
It seems there are at least three potential @AlexandreTunstall how do you feel about just using |
Yes, using Since I'm after a Thanks for introducing me to semialign. |
Motivation
I currently find myself in need of a
Semigroup (ZipList a)
such that:Semigroup (Ap ZipList a)
does not fulfil this need:Surprisingly though, there does not seem to be any such instance in base yet.
Proposal
I propose adding
Semigroup ZipList
andMonoid ZipList
instances that behave as described above.Here's one way of implementing them:
The above implementation seems to follow the
Monoid
laws.I'm suggesting adding these instances directly to
ZipList
rather than another listnewtype
because:Semigroup
forZipList a
that corresponds tozipWith (<>)
already exists asAp ZipList a
.Applicative
instance that would give the desiredSemigroup
underAp
, so I doubt we'll ever want to pair thisSemigroup
with a differentApplicative
.ZipList
.However, one reason to opt for another
newtype
is that people may confuseZipList a
andAp ZipList a
. This could be mitigated by explaining the difference in the documentation.This issue was originally raised as GHC issue 22299.
The text was updated successfully, but these errors were encountered: