-
-
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
Add ContravariantMonoidal #2034
Merged
kailuowang
merged 14 commits into
typelevel:master
from
stephen-lazaro:divisible_decideable
Dec 1, 2017
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0501b2c
Add Divisible
stephen-lazaro 3db8a82
Rename to ContravariantMonoidal, Base on product
stephen-lazaro afd8aef
Make scalastyle happy
d03cfd5
Add mima exceptions
cdf5732
Use SemigroupalArityFunctions and TupleSemigroupal
stephen-lazaro caf2a40
Clean up `ContravariantMonoidal` documentation
stephen-lazaro 81e7f06
Add missing mima exclusions
2e8c20a
No `tut` shadowing, remove extraneous braces
stephen-lazaro a27927d
Increase WriterT coverage, tut:reset
stephen-lazaro 9b09aa4
Use tut:reset correctly
stephen-lazaro 1c14af2
Move composition functions into Applicative
stephen-lazaro 110ac5e
Reorder instances to be more standard
stephen-lazaro f7c4104
Tighten test code for Contravariant derivatives
stephen-lazaro 6e7a1b5
Remove extra allocations, use `on` and `by`
stephen-lazaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cats | ||
|
||
import simulacrum.typeclass | ||
|
||
/** | ||
* [[ContravariantMonoidal]] functors are functors that supply | ||
* a unit along the diagonal map for the `contramap2` operation. | ||
* | ||
* Must obey the laws defined in cats.laws.ContravariantMonoidalLaws. | ||
* | ||
* Based on ekmett's contravariant library: | ||
* https://hackage.haskell.org/package/contravariant-1.4/docs/Data-Functor-Contravariant-Divisible.html | ||
*/ | ||
@typeclass trait ContravariantMonoidal[F[_]] extends ContravariantSemigroupal[F] { self => | ||
/** | ||
* `unit` produces an instance of `F` for any type `A` | ||
* that is trivial with respect to `contramap2` along | ||
* the diagonal | ||
*/ | ||
def unit[A]: F[A] | ||
|
||
def liftContravariant[A, B](f: A => B): F[B] => F[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. This can actually be moved to |
||
ContravariantMonoidal.contramap2(unit[B], _: F[B])(((b: B) => (b, b)) compose f)(self, self) | ||
} | ||
object ContravariantMonoidal extends SemigroupalArityFunctions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wouldn’t repeat
Monoidal
here becauseApplicative
already impliesMonoidal
since they are equivalent (see also this detailed explanation: https://stackoverflow.com/questions/23316255/lax-monoidal-functors-with-a-different-monoidal-structure).Edit: sorry I was wrong. This trait composes a covariant applicative with a contravariant one, so the naming is correct, you can ignore my comment.
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.
The SO was a good read, anyway, it clarified some of the points on different
Monoidal
structures for me, so thank you.