Give helper type families more precise kinds #612
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When promoting a class or instance method, we generate a "helper" type family definition that contains the actual implementation of the class or instance method. Prior to this patch, it was possible that the kind of the helper type family could be more polymorphic than desired. For instance,
singletons-th
would promote this:To this:
Note that GHC would generalize the standalone kind signature of
RightSparrowDefault
to:This is more general than intended, as we want
f
to be of kindType -> Type
instead. After all, we said as much in the standalone kind signature forMyApplicative
! This excessive polymorphism doesn't actively cause problems in today's GHC, but they will cause problems in a future version of GHC that implements GHC#23515. (See #601.)This patch resolves the issue by propagating kind information from the class's standalone kind signature (or, in the case of instance declarations, the instance head) to the helper type family declarations. After this patch, we now generate the following kind for
RightSparrowDefault
(as verified by the newT601a
test case):This piggybacks on machinery that was added in #596 to do most of the heavy lifting.
Resolves the "Overly polymorphic promoted class defaults" section of #601.