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

Refactor functors and related packages #131

Merged
merged 3 commits into from
Feb 5, 2021

Conversation

rhendric
Copy link
Member

@rhendric rhendric commented Feb 4, 2021

This is part of a set of commits that rearrange the dependencies between
multiple packages. The immediate motivation is to allow certain newtypes
to be reused between profunctor and bifunctors, but this particular
approach goes a little beyond that in two ways: first, it attempts to
move data types (either, tuple) toward the bottom of the dependency
stack; and second, it tries to ensure no package comes between
functors and the packages most closely related to it, in order to open
the possibility of merging those packages together (which may be
desirable if at some point in the future additional newtypes are added
which reveal new and exciting constraints on the module dependency
graph).

Description of the change

See discussion in purescript/purescript-profunctor#23.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

This is part of a set of commits that rearrange the dependencies between
multiple packages. The immediate motivation is to allow certain newtypes
to be reused between `profunctor` and `bifunctors`, but this particular
approach goes a little beyond that in two ways: first, it attempts to
move data types (`either`, `tuple`) toward the bottom of the dependency
stack; and second, it tries to ensure no package comes between
`functors` and the packages most closely related to it, in order to open
the possibility of merging those packages together (which may be
desirable if at some point in the future additional newtypes are added
which reveal new and exciting constraints on the module dependency
graph).
Copy link
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

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

Perhaps worth explicitly mentioning the addition of lookup in here too?

@rhendric
Copy link
Member Author

rhendric commented Feb 5, 2021

Good catch! Mentioned.

Copy link
Contributor

@JordanMartinez JordanMartinez left a comment

Choose a reason for hiding this comment

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

Can you fix the instances' names to match naming conventions? Otherwise, this looks ready to merge.

foldr1 _ (Tuple _ x) = x
foldl1 _ (Tuple _ x) = x

instance foldableIdentity :: Foldable1 Identity where
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this follow naming conventions?

- foldableIdentity
+ foldable1Identity

Copy link
Member Author

Choose a reason for hiding this comment

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

There seems to be a local convention of dropping the 1 in the instance names for the semigroup classes; see lines 88 and 93, for example. I tried to stick to that (but, um, I goofed on line 98)—local consistency trumps global conventions, especially for something as inconsequential as instance names.

Copy link
Member

@thomashoneyman thomashoneyman Feb 5, 2021

Choose a reason for hiding this comment

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

It's certainly possible that lines 88 and 93 are themselves oversights; elsewhere in core libraries I am more familiar with seeing instances match the class. For example, the Foldable1 instances here:

https://github.com/purescript/purescript-nonempty/blob/v5.0.0/src/Data/NonEmpty.purs

I don't have strong opinions on instance names (I wish they were automatic!), but it may be better to fix the instance names on lines 88 and 93 rather than go for local consistency. That said, I would personally accept this PR taking either approach.

traverse1 f (Tuple x y) = Tuple x <$> f y
sequence1 (Tuple x y) = Tuple x <$> y

instance traversableIdentity :: Traversable1 Identity where
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

- traversableIdentity
+ traversable1Identity

@@ -42,6 +44,14 @@ instance traversableMultiplicative :: Traversable1 Multiplicative where
traverse1 f (Multiplicative x) = Multiplicative <$> f x
sequence1 = sequence1Default

instance traversableTuple :: Traversable1 (Tuple a) where
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

- traversableTuple
+ traversable1Tuple

@JordanMartinez
Copy link
Contributor

On second thought, let's get this PR merged. The instance name being renamed won't affect things downstream, but we can at least make it possible for @rhendric to open a PR for parallel, and then this migration will be complete, correct?
If we want to change the instance names later, we can do so in a separate PR.

@JordanMartinez
Copy link
Contributor

I've opened #132 to track the 'instance name' issue.

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

4 participants