Skip to content
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 some bifunctors-style newtypes #22

Merged
merged 5 commits into from
Jun 9, 2017
Merged

Add some bifunctors-style newtypes #22

merged 5 commits into from
Jun 9, 2017

Conversation

garyb
Copy link
Member

@garyb garyb commented Jun 9, 2017

The name Cowrap is probably a bit odd, but I haven't come up with anything better yet.

@garyb
Copy link
Member Author

garyb commented Jun 9, 2017

/cc @safareli


-- | Turns a `Profunctor` into a `Invariant` functor by equating the two type
-- | arguments.
newtype Join p a = Join (p a a)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth providing the adjoint, which constructs a profunctor from an invariant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd rather just remove Invariant, but that's a separate, larger conversation 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait! I just realised something, this is purescript-deprecated/purescript-monoid#34 if we provide

instance semigroupJoin :: Semigroupoid p => Semigroup (Join p a) where
  append (Join a) (Join b) = Join (a <<< b)

instance monoidJoin :: Category p => Monoid (Join p a) where
  mempty = Join id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea what the adjoint would look like? I just took a stab at it, but not really sure what I'm doing there and couldn't figure out how to implement dimap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the previous discussion of this here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah! I remember now. Will add that too then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to give it a better name 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cojoin was all I had, I'm not sure it's any better 😆

Copy link
Contributor

@paf31 paf31 Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split possibly? Since we're trying to split the type argument into two.

@paf31
Copy link
Contributor

paf31 commented Jun 9, 2017

👍 LGTM. Curious though - is there a use case for these?

@garyb
Copy link
Member Author

garyb commented Jun 9, 2017

Curious though - is there a use case for these?

Uhh... most of them are pretty speculative 😉

It came from a discussion with @safareli, he was asking if we could impose Functor and Contravariant superclasses, or provide instances for Functor and Contravariant for every Profunctor - since we have endofunctors, no, but I figured providing newtypes for them would "prove" the relationship is there, and perhaps be occasionally useful.

Then when I started on that, I figured that profunctors are still a bifunctors, just not in the purescript sense, so I went back to BF to see which of the various newtypes may translate to PF. So Clown and Joker are definitely a bit 🤷‍♂️, and Join was right up until two minutes ago when I realised it's our abstracted Endo 😆

@paf31
Copy link
Contributor

paf31 commented Jun 9, 2017

Do you think the names Clown and Joker might be confusing though?

@safareli
Copy link

safareli commented Jun 9, 2017

there is already Joker and Clown defined in https://pursuit.purescript.org/packages/purescript-bifunctors

@garyb
Copy link
Member Author

garyb commented Jun 9, 2017

I'm happy to change them, just figured since they work the same way for bifunctors, reusing the names here was reasonable.

@garyb
Copy link
Member Author

garyb commented Jun 9, 2017

There we go, Split sounded good to me.


newtype Split f a b = Split (Exists (SplitF f a b))

data SplitF f a b x = SplitF (a -> x) (x -> b) (f x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we hide the constructors here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good call.

@paf31
Copy link
Contributor

paf31 commented Jun 9, 2017

👍 LGTM, thanks!

@garyb garyb merged commit 3939c48 into master Jun 9, 2017
@garyb garyb deleted the newtypes branch June 9, 2017 19:33
@paf31
Copy link
Contributor

paf31 commented Jun 9, 2017

I just thought - should this have reused the existing newtypes? Bit late now, but probably worth considering.

@garyb
Copy link
Member Author

garyb commented Jun 9, 2017

I just explored that a bit...

  • We could reuse Clown and Joker, defining the instances in Data.Profunctor
  • Wrap doesn't work as it has an overlapping Functor instance (one with Bifunctor and one with Profunctor constraints on p)
  • Join could work, but we'd have to define those "endo" instances with the newtype, which would mean some dependency reordering - it probably works out, but bifunctors and monoid are both near the top of the hierarchy, so I'm a little hesitant to mess with them right now.

I think next time we do breaking releases for all the core libraries we can take a look at it again though 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants