-
Notifications
You must be signed in to change notification settings - Fork 24
instance (Applicative f, Semigroup f) => Semigroup (NonEmpty f a) #18
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
Comments
Is anything wrong with @wereHamster's proposition? Should I provide pull request? |
I have the same question; I've written a non-typeclass version of |
For some reason the assumption in such an implementation that |
Maybe |
Taking this implementation: append ∷ ∀ a f. Semigroup (f a) ⇒ Applicative f ⇒ NonEmpty f a → NonEmpty f a → NonEmpty f a
append (NonEmpty a1 f1) (NonEmpty a2 f2) = NonEmpty a1 (f1 <> pure a2 <> f2) We have: NonEmpty a1 f1 <> (NonEmpty a2 f2 <> NonEmpty a3 f3)
-- using append
NonEmpty a1 f1 <> NonEmpty a2 (f2 <> pure a3 <> f3)
-- using append
NonEmpty a1 (f1 <> pure a2 <> (f2 <> pure a3 <> f3))
-- using associativity of f
NonEmpty a1 ((f1 <> pure a2 <> f2) <> pure a3 <> f3)
-- using append
NonEmpty a1 (f1 <> pure a2 <> f2) <> NonEmpty a3 f3
-- using append
(NonEmpty a1 f1 <> NonEmpty a2 f2) <> NonEmpty a3 f3 So it seems that |
P.S. |
On the other hand |
Is there any reason we couldn't just implement this and swap it out for a weaker constraint afterwards? |
The only problem with this is that we don't know that |
Closed by #50. |
Would be useful to concatenate two
NonEmpty Array a
types together, for example. Is there a reason why it doesn't exist?The text was updated successfully, but these errors were encountered: