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

Functor law hint may be too opinionated #1606

Open
pbrisbin opened this issue Jul 8, 2024 · 1 comment
Open

Functor law hint may be too opinionated #1606

pbrisbin opened this issue Jul 8, 2024 · 1 comment

Comments

@pbrisbin
Copy link
Contributor

pbrisbin commented Jul 8, 2024

I think with #1540, we are now hitting Functor law hints more than before.

As an example, I was just prompted to change some code from:

    PlatformSettingsYaml
      <$> (Last <$> parseStackName o)
      <*> o .:? "stackDescription"
      <*> o .:? "docker"
      <*> o .:? "assets"

To:

    PlatformSettingsYaml . Last
      <$> parseStackName o
      <*> o .:? "stackDescription"
      <*> o .:? "docker"
      <*> o .:? "assets"

This has come up 5 or so times in one code base, all of this general form: an applicative record construction where the first field happens to need some wrapper over an applicative action.

I find the former code to be clearer because it keeps that wrapping (Last <$>) as part of the "field" of the applicative build. Moving the Last out and up to PlatformSettingsYaml . Last kind of just breaks my brain, to use (.) with a constructor function of many arguments diverges too far from the (f . g) x form that I can't grok it.

It does compile of course, so it's not "wrong" at all, I just wonder:

  1. Is this the most common kind of code this lint catches, and
  2. Am I alone in thinking it makes the code less readable?

If the answer is yes/yes, maybe it should be ignored by default?

@ndmitchell
Copy link
Owner

Fair. I guess maybe disable it for now? Better to not suggest, than suggest something that is confusing.

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

No branches or pull requests

2 participants