Skip to content

Conversation

armanbilge
Copy link
Member

Alternative to #6137 that also manages to relax the constraints on Client#translate.

@mergify mergify bot added series/0.23 PRs targeting 0.23.x module:client labels Mar 18, 2022
run(
req.mapK(gK)
).mapK(fk)
.map(_.mapK(fk))
)
}

private def liftMonadCancel[G[_]](
Copy link
Member

Choose a reason for hiding this comment

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

It seems that the MonadCancel can have the mapK method or even this lift method. Did that discuss on discord or somewhere? I will be grateful for the link 🙏🏻
Anyway, I feel that this lift method is super-specific to have it within the client package. Maybe there is a more appropriate fp.utils package?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, MonadCancel can have an imapK method :)

Yeah, bit of long discussion 😅
I propose my idea for this PR here:
https://discord.com/channels/632277896739946517/839254871646404638/954226420601716736
Then we discuss it here:
https://discord.com/channels/632277896739946517/839254871646404638/954238156767625266

I do agree this is weird one for Client 😆 @ChristopherDavenport is very suspicious about it though, which suggests we should keep it private-scoped to a small area. I can ask if CE will accept imapK addition.

Copy link
Member

Choose a reason for hiding this comment

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

Can anyone summarize the objection? Neither PR has a unit test: it would be great to see evidence that they satisfy the aim. Or if this approach doesn't work, a test that shows how it fails.

This one better fits the golden rule of software quality if it indeed works.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ChristopherDavenport on Discord:

So I agree that will work, but I have been told and so practice that it is bad to override a typeclass like that.
As canonically a typeclass should have a single implementation for a type.

https://discord.com/channels/632277896739946517/839254871646404638/954238688676704328

He said he will throw up a unit test today.

Choose a reason for hiding this comment

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

Tests are push to my branch, feel free to steal them over 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.

My implementation passes @ChristopherDavenport's tests.

Copy link
Member

Choose a reason for hiding this comment

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

On the theoretical question, is it any worse than:

Choose a reason for hiding this comment

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

I believe private[this] is more private than private. As mentioned before I'm not theory person and this version is much cleaner than mine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
private def liftMonadCancel[G[_]](
private[this] def liftMonadCancel[G[_]](

Copy link
Member

Choose a reason for hiding this comment

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

private is also accessible from other instances of Client. private[this] is accessible only from the same instance of Client. Furthermore, private[this] is direct field access instead of through an accessor method. I think that change is conservative, and therefore good, until everyone is comfortable with it.

On theory, there's a nice Haskell discussion of Applicative.monoid by Gabriella Gonzalez.

I think there's nothing wrong with providing explicit derived instances like this, and let users promote them to implicit if they are judged to be the canonical instance for the type, or tuck them away as done here when they do the right thing.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

This looks good to me. It does what it says on the tin, and the controversial bits are private in case the theoretical objection manifests in a practical way.

Co-authored-by: Ross A. Baker <ross@rossabaker.com>
@armanbilge armanbilge merged commit ca39ff9 into http4s:series/0.23 Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:client series/0.23 PRs targeting 0.23.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants