-
Notifications
You must be signed in to change notification settings - Fork 43
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 arrow-related instances #111
Conversation
Strong: TambaraSum, PastroSum, Day Costrong: Star, TambaraSum, Rift, Ran, Codensity Choice: Day Cochoice: Rift, Ran, Codensity Category: CofreeTraversing, Costar Arrow: Star, CofreeTraversing, Coyoneda, TambaraSum ArrowZero: Star, CofreeTraversing, Yoneda, Coyoneda, TambaraSum ArrowPlus: WrappedArrow, Star, CofreeTraversing, Yoneda, Coyoneda, TambaraSum ArrowChoice: Star, CofreeTraversing, Yoneda, Coyoneda, TambaraSum ArrowApply: Star, Yoneda, Coyoneda ArrowLoop: Star, Yoneda, Coyoneda, TambaraSum
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.
Thanks! Can you mention these changes in the CHANGELOG
?
src/Data/Profunctor/Types.hs
Outdated
-- | | ||
-- - 'Arrow' is equivalent to 'Category' | ||
-- && t'Data.Profunctor.Strong.Strong'. | ||
-- - 'ArrowChoice' is equivalent to 'Category' | ||
-- && t'Data.Profunctor.Strong.Strong' && t'Data.Profunctor.Choice.Choice'. | ||
-- - 'ArrowLoop' is equivalent to 'Category' | ||
-- && t'Data.Profunctor.Strong.Strong' && t'Data.Profunctor.Strong.Costrong'. | ||
-- | ||
-- This newtype allows 'Profunctor' classes to be used with types that only | ||
-- implement @base@'s arrow classes. |
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.
These Haddocks are now somewhat indirect, as they begin with a list of relationship between base
classes and profunctor
classes, and then they are followed with an explanation of what the WrappedArrow
type actually is. I think it should be the other way around: first say what WrappedArrow
is, and then use that to motivate the relationships between the classes.
We know that:
Arrow
=Strong
+Category
,ArrowChoice
=Choice
+Strong
+Category
ArrowLoop
=Costrong
+Strong
+Category
The
WrappedArrow
class allows usingprofunctors
classes with types that only implementbase
arrows instances. However sinceprofunctors
depends onbase
, the expectation is that anything that is a Strong Category should also be an Arrow, etc, else you can't use arrow syntax!Hence I've added the following instances:
ArrowPlus p => ArrowPlus (WrappedArrow p)
-- there wasArrowZero
, but notArrowPlus
for some reasonStar
MonadFix f => Costrong (Star f)
-- derived fromKleisli
Monad f => Arrow (Star f)
-- derived from its strengthMonadPlus f => ArrowZero (Star f)
-- usingAlternative
(we have aMonad
superclass constraint anyway, henceMonadPlus
)MonadPlus f => ArrowPlus (Star f)
-- usingMonadPlus
Monad f => ArrowChoice (Star f)
-- derived from its choiceMonad f => ArrowApply (Star f)
-- derived fromKleisli
MonadFix f => ArrowLoop (Star f)
-- derived from the aforementioned costrengthCostar
Comonad f => Category (Costar f)
-- derived fromCokleisli
CofreeTraversing
Category p => Category (CofreeTraversing p)
-- things of the formforall x. p (x ⊗ a) (x ⊗ b)
(end comonads) naturally form a category(Category p, Profunctor p) => Arrow (CofreeTraversing p)
-- derived from its strength(ArrowZero p, Profunctor p) => ArrowZero (CofreeTraversing p)
-- natural for "end comonads"(ArrowPlus p, Profunctor p) => ArrowPlus (CofreeTraversing p)
-- natural for "end comonads" (the arrows are always in parallel)(Category p, Profunctor p) => ArrowChoice (CofreeTraversing p)
-- derived from its choiceTambaraSum
Strong p => Strong (TambaraSum p)
-- looks asymmetric, but shouldn't be, given lawfulStrong p
Costrong p => Costrong (TambaraSum p)
-- same benign asymmetryArrow p => Arrow (TambaraSum p)
-- derived from aforementioned strengthArrow p => ArrowChoice (TambaraSum p)
-- derived from aforementioned choiceArrowZero p => ArrowZero (TambaraSum p)
-- natural for "end comonads"ArrowPlus p => ArrowPlus (TambaraSum p)
-- natural for "end comonads"PastroSum
Strong p => Strong (PastroSum p)
-- checks outYoneda
-- degenerates whenProfunctor p
, hence much like its other instances we just extract and proreturn(Arrow p, Profunctor p) => Arrow (Yoneda p)
-- derived from its strength(ArrowZero p, Profunctor p) => ArrowZero (Yoneda p)
(ArrowPlus p, Profunctor p) => ArrowPlus (Yoneda p)
(ArrowChoice p, Profunctor p) => ArrowChoice (Yoneda p)
-- derived from its choice(ArrowApply p, Profunctor p) => ArrowApply (Yoneda p)
(ArrowLoop p, Profunctor p) => ArrowLoop (Yoneda p)
-- derived from its costrengthCoyoneda
-- likewise we just return and proextract(Arrow p, Profunctor p) => Arrow (Coyoneda p)
-- derived from its strength(ArrowZero p, Profunctor p) => ArrowZero (Coyoneda p)
(ArrowPlus p, Profunctor p) => ArrowPlus (Coyoneda p)
(ArrowChoice p, Profunctor p) => ArrowChoice (Coyoneda p)
-- derived from its choice(ArrowApply p, Profunctor p) => ArrowApply (Coyoneda p)
(ArrowLoop p, Profunctor p) => ArrowLoop (Coyoneda p)
-- derived from its costrengthRift
(Strong p, Costrong q) => Costrong (Rift p q)
-- checks out(Choice p, Cochoice q) => Cochoice (Rift p q)
-- checks outRan
(Strong p, Costrong q) => Costrong (Ran p q)
-- same asRift
(Choice p, Cochoice q) => Cochoice (Ran p q)
-- same asRift
Codensity
(Strong p, Costrong p) => Costrong (Codensity p)
-- derived fromRan p p
(Choice p, Cochoice p) => Cochoice (Codensity p)
-- derived fromRan p p
Day
(Profunctor p, Strong q) => Strong (Day p q)
-- this one could alternatively be defined usingp
's strength, but I figured it should target the same argument as doesProfunctorMonad
, alsoswapped
is right there.(Choice p, Choice q) => Choice (Day p q)
Things like
Category (Pastro p)
requireStrong p
at which pointPastro p <-> p
and if you want an arrow you can just extract, so I've decided to not bother with that. Likewise withCategory (FreeTraversing p)
.