Skip to content

Refactor Ord instances#3902

Merged
hdgarrood merged 3 commits intopurescript:masterfrom
milesfrain:ord-reorg
Dec 27, 2020
Merged

Refactor Ord instances#3902
hdgarrood merged 3 commits intopurescript:masterfrom
milesfrain:ord-reorg

Conversation

@milesfrain
Copy link
Copy Markdown
Contributor

Follow-up to #3899 (comment)

Also applied the orderOf strategy to a few other places.

Some additional discussion about strategies for skipping SourceSpan comparisons in #3265

-- to have mismatched behavior.
instance Eq Binder where
(==) NullBinder NullBinder = True
(==) NullBinder _ = False
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This block of changes moves all lines like these to a final:

_ == _ = False

NullBinder == NullBinder =
True
(LiteralBinder _ lb) == (LiteralBinder _ lb') =
lb == lb'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure what the line-wrapping coding standard is. Could either:

  • Use one line for each expression. Lines may grow long.
  • Break after cutoff point, e.g. 80 characters. I feel this adds inconsistency to the structure.
  • Break at each assignment. What's done in this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Breaking at each assignment like you've done here looks good to me. These things aren't really consistent across the compiler codebase at the moment.

data DeclarationRef
-- |
-- A type constructor with data constructors
-- A type class
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reordered to match linting order

Comment on lines -226 to -228
-- enable sorting lists of explicitly imported refs when suggesting imports in linting, IDE, etc.
-- not an Ord because this implementation is not consistent with its Eq instance.
-- think of it as a notion of contextual, not inherent, ordering.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need this comment anymore, since it now follows the order of the constructors.

compareType (KindApp {}) _ = LT
compareType _ (KindApp {}) = GT

compareType (ForAll _ a b c d) (ForAll _ a' b' c' d') = compare a a' <> compareMaybeType b b' <> compareType c c' <> compare d d'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here's an example of using long lines for each expression. This is another good candidate for the above coding style question.

@kl0tl
Copy link
Copy Markdown
Member

kl0tl commented Jun 26, 2020

Is there a reason for not defining the Eq instances of Binder and DeclarationRef via their Ord instance and defining eqType via compareType?

@natefaubion
Copy link
Copy Markdown
Contributor

Is there a reason for not defining the Eq instances of Binder and DeclarationRef via their Ord instance and defining eqType via compareType?

Maybe efficiency? I don't think we've ever measured it.

Copy link
Copy Markdown
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.

Looks good, thanks!

@hdgarrood
Copy link
Copy Markdown
Contributor

As is, this change already removes a bunch of code so I'm happy to leave the question of whether we should define Eq via Ord for later.

Copy link
Copy Markdown
Member

@thomashoneyman thomashoneyman left a comment

Choose a reason for hiding this comment

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

👍 thanks for this work, @milesfrain!

@hdgarrood hdgarrood merged commit 62c5862 into purescript:master Dec 27, 2020
@milesfrain milesfrain deleted the ord-reorg branch December 27, 2020 19:35
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.

5 participants