-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Follow up to #751 #757
Follow up to #751 #757
Changes from 2 commits
f6ded9e
5c67d9e
b415188
ec82947
4aab63e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,15 @@ import simulacrum.typeclass | |
*/ | ||
def empty[A]: F[A] | ||
|
||
/** | ||
* Compose two MonoidK intsances. | ||
*/ | ||
def compose[G[_]](implicit GG: MonoidK[G]): MonoidK[λ[α => F[G[α]]]] = | ||
new CompositeMonoidK[F, G] { | ||
implicit def F: MonoidK[F] = self | ||
implicit def G: MonoidK[G] = GG | ||
} | ||
|
||
/** | ||
* Given a type A, create a concrete Monoid[F[A]]. | ||
*/ | ||
|
@@ -38,3 +47,13 @@ import simulacrum.typeclass | |
def combine(x: F[A], y: F[A]): F[A] = self.combine(x, y) | ||
} | ||
} | ||
|
||
trait CompositeMonoidK[F[_],G[_]] | ||
extends MonoidK[λ[α => F[G[α]]]] { | ||
|
||
implicit def F: MonoidK[F] | ||
implicit def G: MonoidK[G] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't actually use this We can freely take a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point ... I'll remove the constraint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is usage of the from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this comment. I'm saying that I think we should be able to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is that there is usage of the form There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I guess that seems to be a bit misleading to me. You aren't really composing the instances at all. You are just grabbing a type parameter from the second one. My inclination would be to have @non I think you originally added the Edit: for the cases where the evidence isn't required, I'm completely happy with calling these something other than |
||
|
||
def empty[A]: F[G[A]] = F.empty | ||
def combine[A](x: F[G[A]], y: F[G[A]]): F[G[A]] = F.combine(x, y) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
GG
constraint can be relaxed toApplicative
while still returning anAlternative
(also onCompositeAlternative
below).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed ... updated accordingly ...