-
Notifications
You must be signed in to change notification settings - Fork 13
Re-use Bifunctor
newtypes where appropriate
#23
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
Comments
@joneshf, @MonoidMusician and I were discussing on Slack and here's what we came up with. @joneshf suggested making the following a superclass of both class Functor1 f where
rmap :: forall a b c. (b -> c) -> f a b -> f a c We could then define all of the following in
All of these can have
The only potentially difficult instance is A nice bonus of this is that there is no longer any need to have two separate |
class (forall x. Functor (f x)) <= Bifunctor f where
bimap :: forall a b c d. (a -> b) -> (c -> d) -> f a c -> f b d
lmap :: forall a b c. (a -> b) -> f a c -> f b c
class (forall x. Functor (f x)) <= Profunctor f where
dimap :: forall a b c d. (a -> b) -> (c -> d) -> f b c -> f a d
lcmap :: forall a b c. (a -> b) -> f b c -> f a c |
Right, but I think, even if we had quantified constraints, it can still be useful sometimes to draw attention to the fact that you're mapping over the right-hand type variable in a type of kind |
@hdgarrood Can EDIT: yes it can, |
Not really important, but I think the class Functor1 t where
map1 ∷ ∀ f g. (f ~> g) → t f → t g |
Looking over this issue, so the final class name should be |
Given purescript/purescript-bifunctors#17, should we rather name it FunctorRight (or rename ApplyLeft, ApplicativeLeft, BindLeft and MonadLeft to ApplyL, ApplicativeL, BindL and MonadL)? |
Using full words rather than abbreviations here sounds good to me. |
I'll get started on this. |
instance functorFlip :: Bifunctor p => Functor (Flip p a) where
map f (Flip a) = Flip (lmap f a) |
First PR here: purescript/purescript-functors#27 |
Why move |
Just wanted to remind people here that this PR is ready for review: purescript/purescript-functors#27 |
Good point. I think moving only the types that can be both bifunctors and profunctors to |
I posted a summary of the problem here, but here's a graph showing the nuances (at least, to my knowledge). Is the "Desired Dependency Graph" correct? |
In the desired world, what will happen to (For types that are this interrelated, I wonder if these package divisions are too fine-grained.) |
I find it a bit weird having functors depending on bifunctors and profunctor, I think having it the other way around (having both bifunctors and profunctor depend on functors) would make more sense to me. I guess that would probably require moving bifunctors and profunctor so that they depend on both either and tuples, and moving all of the bifoldable and bitraversable instances out of foldable-traversable and into bifunctors? Does that sound like it would work? |
It can. I'm producing a final graph that helps me understand the full changes we'll be making. |
Maybe we could merge just functors, bifunctors, profunctors? Or is that too far? I'm more of a fan of granularity in core libraries than some I think, but it seems like maybe they don't need to all be separate in this case - they're all flavours of functor in the end. |
Merging those three libraries all sounds reasonable to me, yeah. Then I think the only rearranging that needs to happen is for the Bifoldable and Bitraversable instances for the Clown, Joker, etc types to move from foldable-traversable to this new functors library. (I think "functors" is probably still an appropriate name?) |
Yeah 👍 merging into But yes, true! Assuming the instances and whatnot all make sense too. |
If we're going to go with that approach (merging these into one library), I'm assuming the package graph would look like this then? If that's the case, then should we also throw |
I am suggesting that the Bifoldable and Bitraversable classes stay in foldable-traversable. It’s just the instances for the data types which now live in |
Yeah, be consistent. We'll fix it in the release if it needs to be. Based on Harry's comment above, I don't think we'll make a change. |
merged, awesome, now it's left to fix
in and
in (that's all I have found in my local projects) |
We have a few more PRs to merge in the core libraries before it's time to start hunting down breaks elsewhere. After #41, there will be PRs for |
Only one more to go. |
I've opened purescript/package-sets#807 to determine what else was affected by these changes. |
Ok, looks like everything works now. I believe we can close this issue. Thanks @rhendric for all your work! Your approach was better than the one I proposed. |
could someone tell where is the I see
but it's not there
|
It says
😄 It was there to provide a |
@garyb aaaaaa, tnx! |
I think deleting Wrap makes slightly less sense now that we discarded the plan of introducing FunctorRight, actually.. maybe we should reintroduce it after all. On reflection I think Wrap has a valid use case when you have a generic Bifunctor and you want to use it with some function which has a Functor constraint. |
My preferred solution for this is the thing I posted way back at the start of this thread: #23 (comment) But since that isn't possible right now, I like the |
Yeah, agreed, it'd be nice to have quantified constraints but in the meantime Wrap is probably best. |
(sorry!) |
In principle I halfway agree with you? There's a part of me that wants to advance the position that every class should have a newtype associated with it, for those times when you want to say that any instance of class X can be used as a class Y but you don't want to create a universal instance. It's a useful trick for dealing with the limitations of classes and instances, and maybe it should be more widely adopted. But on the other hand, look at this commit @srghma just linked. Getting rid of |
That's a good point, I hadn't looked at the commit. We could say we'll keep leaving them out for now and consider adding them back if we come across a situation where there isn't a good way of rewriting the code, then? |
If we don't add Gary's in agreement with leaving it out. Harry seems to be ok with leaving it out. I'm curious to see whether @rhendric's claim holds true, so I think it should be left out, too. With that being said, can this issue be closed? |
I think so 🙂 |
For the next round of breaking-change releases.
See #22 (comment)
The text was updated successfully, but these errors were encountered: