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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use explicit deriving strategies where it's ambiguous #3022
Conversation
@@ -180,3 +158,27 @@ executables: | |||
- unison-util | |||
- unison-util-relation | |||
- unison-pretty-printer | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved this to the bottom because it's the most boring clause, I think. Also, I may have added an extension or two, for consistency with other packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider a defaults.yaml for the monorepo for this in the future I think, you can then just import it into each package.yaml, we did it at Wire and it worked out well 馃槃
@@ -477,9 +477,13 @@ data ANormalF v e | |||
-- Types representing components that will go into the runtime tag of | |||
-- a data type value. RTags correspond to references, while CTags | |||
-- correspond to constructors. | |||
newtype RTag = RTag Word64 deriving (Eq, Ord, Show, Read, EC.EnumKey) | |||
newtype RTag = RTag Word64 | |||
deriving stock (Eq, Ord, Show, Read) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrmm, are you sure about the Read instance? The stock one would expect RTag 42
whereas the newtype instance would be 42
; Same for CTag below;
I guess it depends on where and how this is used and whether it expects to read numbers or just requires a correct roundtrip through String.
Even if it was currently behaving as a stock instance that doesn't necessarily mean that's what Dan intended 馃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Read
was stock-derived before and after this PR, so that'd be "RTag 42". Seems right to me, especially because of the (informal?) rule that Read
should agree with Show
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double-checked and these Read instances are unused (everything still compiles after removing them), I'm guessing someone just went a little derive-happy so I'd personally advocate for removing it haha.
I know the "expected" behaviour is for it to agree with Show, but in my experience using Read
for anything other than primitive types is an anti-pattern, better to write a proper parser, or a String -> Either String a
function IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Yeah, I don't use Read
myself, but I didn't author this code originally. Let's maybe suggest removing it in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check the usage of those Read instances please, but otherwise looks good.
TBH I wish there was a "require-deriving-strategy" warning we could enable, could probably write a regex for it haha.
What do you mean check usage of the Read instances? Edit: oh -- I see now, your other comment |
Overview
This PR adds a few explicit
stock
/newtype
deriving strategies where they were ambiguous before.These clauses were previously causing warnings when loading more than one component into ghci (i.e.
stack ghci
), because:DeriveAnyClass
andGeneralizedNewtypeDeriving
enabled, GHC emits a warning for some deriving clauses indicating that it's defaulting toDeriveAnyClass
for some type classes, but you should be explicit about which strategy to use.unison-parser-typechecker
only hasGeneralizedNewtypeDeriving
enabled, but some other package(s) haveDeriveAnyClass
stack ghci
, it just combines all of the flags/extensions together.With this PR, you should be able to
stack ghci
without warning. (Better would be to have the same set of extensions enabled in every package 馃槃)