Skip to content

Conversation

milesfrain
Copy link
Contributor

@milesfrain milesfrain commented Jan 11, 2021

Description of the change

Adds Eq1 and Ord1 instances to NonEmptyList and LazyNonEmptyList
Fixes #186


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)

@milesfrain
Copy link
Contributor Author

CI shows that the Lazy version of this change fails to compile, but the non-Lazy version works fine. Don't know why.

@milesfrain milesfrain marked this pull request as ready for review January 11, 2021 08:37
derive newtype instance ordNonEmptyList :: Ord a => Ord (NonEmptyList a)

instance eq1NonEmptyList :: Eq1 NonEmptyList where
eq1 (NonEmptyList lhs) (NonEmptyList rhs) = eq1 lhs rhs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was hoping this shorthand would work, but it does not:

eq1 = over NonEmptyList eq1

Copy link
Member

Choose a reason for hiding this comment

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

I've seen a number of cases where omitting arguments in an instance doesn't work. But I think it's arguably better to include the arguments explicitly in any case.

Copy link
Contributor Author

@milesfrain milesfrain Jan 14, 2021

Choose a reason for hiding this comment

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

I'd argue that the shorthand version is better, since it protects you from making a mistake like this:

compare1 (NonEmptyList rhs) (NonEmptyList lhs) = compare1 lhs rhs

@milesfrain
Copy link
Contributor Author

milesfrain commented Jan 14, 2021

Should these changes be tested, and if so, I guess I should also add the same tests to the empty-able lists too?
Also, holding off on editing the changelogs for each of these pending PRs, since that's going to cause a merge conflict after each PR is merged. Will do that right before 0.14

Copy link
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

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

I don’t think these need tests - the type system helps us enough here (via parametricity) that I think we can be confident these are doing the right thing without needing additional tests.

@hdgarrood
Copy link
Contributor

hdgarrood commented Jan 14, 2021

Actually let’s include the changelog updates in each PR please; the merge conflicts that would be introduced will all be very easy to fix.

@hdgarrood
Copy link
Contributor

Thank you!

@hdgarrood hdgarrood merged commit e992892 into purescript:master Jan 14, 2021
@milesfrain milesfrain deleted the non-empty-eq1-ord1 branch January 14, 2021 20:07
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.

Add Eq1 and Ord1 instances to NonEmptyList and LazyNonEmptyList

3 participants