-
Notifications
You must be signed in to change notification settings - Fork 49
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 Crosswalk instances for: NonEmpty, Proxy, Const, Functor.Sum, These1 #193
base: master
Are you sure you want to change the base?
Conversation
@phadej Thoughts? |
@phadej gentle prod? |
Do you disagree with some of the instances? Would it help to split this into 6 pull requests? |
semialign/src/Data/Crosswalk.hs
Outdated
Fill deff fs <*> Fill defx xs | ||
= Fill (deff defx) (alignWith (uncurry id . fromThese deff defx) fs xs) | ||
|
||
instance Traversable t => Crosswalk (MaybeT t) where |
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.
This doesn't look right (even the tests pass). MaybeT t
is essentially Compose t Maybe
, and I't expect the instance to be exactly that.
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 look at sequenceL @Maybe
as a sort of generalization of catMaybes
(that returns Nothing if input was all Nothings), then Crosswalk (Compose f g)
first removes Nothings from g
's, and if that removed all Nothings, it then removes the g
altogether from f
, using Crosswalk f
.
Crosswalk (MaybeT f)
doesnt do this last step, hence being traversable is sufficient.
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.
So Crosswalk (MaybeT t)
behaves differently than Compose t Maybe
? If it's so, I'd rather not add this instance at all.
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. It doesn't have to be on the MaybeT
type constructor specifically (could be a newtype wrapper), but an instance that behaves like this is immensely useful, because it allows implementing sequenceL
for any type that can implement catMaybes
(witherable):
sequenceL @t xs = catMaybes @t . runMaybeT <$> sequenceL @(MaybeT t) (MaybeT (Just <$> xs))
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.
Are you claiming that every Witherable
is also Crosswalk
?
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.
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.
Thoughts?
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 it's so, I'd rather not add this instance at all.
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've removed it from this PR, maybe let's have a separate discussion about it.
No description provided.