-
-
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 Align typeclass (#1263) #1755
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1755 +/- ##
==========================================
+ Coverage 94.2% 94.28% +0.08%
==========================================
Files 256 260 +4
Lines 4207 4255 +48
Branches 84 85 +1
==========================================
+ Hits 3963 4012 +49
+ Misses 244 243 -1
Continue to review full report at Codecov.
|
Thanks @julianmichael! I personally really like the Do you have any thoughts on what the implications are on |
No problem at all @ceedubs. My main motivation for this PR was I wanted easy zipping and this seemed like the first step. So I'm thinking about how to do this so it'd fit well with a
I'm kind of biased toward bringing Regardless of that, I think it could make sense to have two versions of OTOH, if including |
@julianmichael Thanks for the detailed thoughts! I agree with you that a version without I'm also a little partial to |
Sorry I dropped the ball on this one. Let's see if we can make a final decision on |
I think those two type classes are coming back to core #2405, once merged, this would be unblocked. We are probably going to rush for a 1.3 release. @julianmichael let me know if you want to try squeeze it in or take your time and aim for the next 1.4 release. |
Cool! Would rather not rush it. We seem to have a lot of new stuff in addition to |
Closing stale PRs. Feel free to reopen if there is interest to revive the effort. |
Addresses #1263.
Design taken from the Data.Align Haskell package. Implementing this raised some issues:
zip
andzipWith
. I haven't tried to prove it, but you might even be able to show that the resulting implementation ofzip
satisfies the reasonable law of being a left inverse tounzip
.nil
seems redundant withempty
in MonadFilter and MonoidK. Probably it should also be calledempty
... but notably it just adds to the weirdness of having several different "empties", some of which are forced to converge to the same thing. On that note, we probably want another law saying that these empties have to coincide.It seems there has been some discussion both of adding
empty
to FunctorFilter and removing FunctorFilter entirely. I think it might be nice to have a Zip typeclass, in which case retaining FunctorFilter might be useful for relating the two, though maybe that should just be done with MonadCombine or something.On the subject of zipping, if in the future we wished to have Naperian functors (which I think would be nice too, though maybe that's more the kind of thing to leave in a third-party lib), then Align would only be able to serve as a generalization of it if we removed
nil
from the typeclass. Furthermore, in the Haskell documentation there is the observation that an Align instance makes a functor F lax monoidal wrt the cartesian monoidal structure on Kleisli[Option, ?, ?] if the functor already admits a function(A -> Option[B]) -> F[A] -> F[B]
, which basically means FunctorFilter. But in that case, we basically already get ournil
value too; you just need to ensure the extra law thatnil
is an identity ofalign
.So maybe it'd be best to remove
nil
from Align and add a Zip typeclass that inherits from it and FunctorFilter, which addsempty
and the relevant laws as well aszip
andzipWith
. This captures the familiar notion of zipping from lists, etc. quite well, so I think it's appropriate to use the namezip
for it. For other notions of zipping, we already have Applicative functors, and could potentially add Naperian functors for a sort of "guaranteed full zip" where the shape of both arguments and the result is always the same.Thoughts on this? I'm especially unsure about it because the FunctorFilter/MonadCombine situation seems to be changing.