Skip to content

Add Eq1 Ord1 to NonEmptyList LazyNonEmptyList #188

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

Merged
merged 4 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Added `Eq1` and `Ord1` instances to `NonEmptyList` and `LazyNonEmptyList` (#188)

Bugfixes:

Expand Down
6 changes: 6 additions & 0 deletions src/Data/List/Lazy/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ derive instance newtypeNonEmptyList :: Newtype (NonEmptyList a) _
derive newtype instance eqNonEmptyList :: Eq a => Eq (NonEmptyList a)
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


instance ord1NonEmptyList :: Ord1 NonEmptyList where
compare1 (NonEmptyList lhs) (NonEmptyList rhs) = compare1 lhs rhs

instance showNonEmptyList :: Show a => Show (NonEmptyList a) where
show (NonEmptyList nel) = "(NonEmptyList " <> show nel <> ")"

Expand Down
3 changes: 3 additions & 0 deletions src/Data/List/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ derive instance newtypeNonEmptyList :: Newtype (NonEmptyList a) _
derive newtype instance eqNonEmptyList :: Eq a => Eq (NonEmptyList a)
derive newtype instance ordNonEmptyList :: Ord a => Ord (NonEmptyList a)

derive newtype instance eq1NonEmptyList :: Eq1 NonEmptyList
derive newtype instance ord1NonEmptyList :: Ord1 NonEmptyList

instance showNonEmptyList :: Show a => Show (NonEmptyList a) where
show (NonEmptyList nel) = "(NonEmptyList " <> show nel <> ")"

Expand Down