-
Notifications
You must be signed in to change notification settings - Fork 14
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 VoidProfunctor class #54
Open
tomjaguarpaw
wants to merge
1
commit into
master
Choose a base branch
from
voidprofunctor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ module Data.Profunctor.Product.Class where | |
|
||
import Data.Profunctor (Profunctor) | ||
import qualified Data.Profunctor as Profunctor | ||
import Data.Void (Void) | ||
|
||
--- vv These are redundant imports but they're needeed for Haddock | ||
--- links. AIUI Haddock can't link to something you haven't imported. | ||
|
@@ -94,7 +95,18 @@ class Profunctor p => ProductProfunctor p where | |
f ***! g = (,) `Profunctor.rmap` Profunctor.lmap fst f | ||
**** Profunctor.lmap snd g | ||
|
||
-- | In the future 'VoidProfunctor' will be a superclass of | ||
-- 'SumProfunctor'. | ||
class Profunctor p => VoidProfunctor p where | ||
-- | 'Data.Profunctor.Profunctor' version of | ||
-- 'Data.Functor.Contravariant.Divisible.lose'. @'lost' = loseP id@ | ||
-- is the unit of @('+++!')@. | ||
loseP :: (a -> Void) -> p a b | ||
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. Kinda matches the shape of the proposed |
||
|
||
-- | 'Data.Profunctor.Profunctor' version of | ||
-- 'Data.Functor.Contravariant.Divisible.lost'. | ||
lostP :: VoidProfunctor p => p Void b | ||
lostP = loseP id | ||
|
||
class Profunctor p => SumProfunctor p where | ||
-- Morally we should have 'zero :: p Void Void' but I don't think | ||
-- that would actually be useful | ||
(+++!) :: p a b -> p a' b' -> p (Either a a') (Either b b') |
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
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.
Should this be the other way around? Looking at the
semigroupoids
PR, they have:Should the eventual goal be a hierarchy more like:
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.
Interesting. I didn't expect that. If we really want to do the superclassing in that direction then we can do it now with no backwards compatibility changes!
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.
If we have a superclass relationship between
SumProfunctor
andVoidProfunctor
, it should be this one. "Providing a unit" is almost always done with a subclass (Semigroup => Monoid
etc.) as it lets you write laws in terms of superclass operations that you know you have.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.
Yes, that rationale makes sense to me, thanks! I guess I can also add a superclass of
ProductProfunctor
with methodpureP
. Perhaps I can addpurePP = pureP
as a default and eventually removepurePP
.On the other hand this suggests the names need work. The names
UnitProfunctor
andVoidProfunctor
no longer capture everything the classes do.ApplicativeProfunctor
from your "Option 2" now sounds good to me, but I preferDecidableProfunctor
toConcludeProfunctor
. What do you think?What do you think?
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.
If you have
pureP
, you haveunitP
, so it needs to be on theUnitProfunctor
subclass, becuaseI think I like the
{Sum,Void,Product,Unit}Profunctor
names better, because to me that's the fundamental idea being captured: you're tying pairs of profunctors together in interesting ways, and sometimes you have units for these operations. From there, you can recover a bunch of familiar-looking operations from theApplicative
/Divisible
/Decidable
world, but I don't feel like any of them are compelling enough to take over the class names. Also, it makes the package name confusing if there's noProductProfunctor
class any more.