Display inferred kind signatures in HTML docs#4119
Display inferred kind signatures in HTML docs#4119JordanMartinez merged 17 commits intopurescript:masterfrom JordanMartinez:insertInferredKindSigsIntoDocs
Conversation
|
Pretty sure this is ready for review. I still need to update the changelog to account for this PR. |
| kindFunctionType = P.TypeApp () kindPrimFunction kindPrimType | ||
|
|
||
| -- | | ||
| -- Returns True if the inferred kind signature follows this |
There was a problem hiding this comment.
How about calling this function isUninteresting and saying that an "uninteresting" kind is a kind of the form:
TypeConstraintType -> KwhereKis uninteresting.
I think that makes it clearer which kinds are included, and I think it will make the code a little easier to read.
There was a problem hiding this comment.
Ah, thanks! That's a much better name.
|
This looks great 👍 it looks to me like we will currently only hide uninteresting kinds if they have been inferred, so I think the only thing left to change is to additionally hide uninteresting kinds which are explicitly declared, if that's what we want to do (and I think it probably is, judging by the discussion in #4117?) |
tests/TestDocs.hs
Outdated
| , ShouldHaveKindSignature (n "KindSignatureDocs") "TShown" "data TShown :: (Type -> Type) -> Type -> Type -> Type" | ||
| , ShouldHaveKindSignature (n "KindSignatureDocs") "NShown" "data NShown :: Type -> (Type -> Type) -> Type -> Type" | ||
| , ShouldHaveKindSignature (n "KindSignatureDocs") "CShown" "data CShown :: (Type -> Type) -> Type -> Type -> Type" |
There was a problem hiding this comment.
As the failed build shows, these expectations should be changed to have the correct keywords.
| P.TypeApp _ t1 t2 | t1 == kindFunctionType -> | ||
| isFunctionTypeStarTerminal t2 | ||
| x | ||
| | x == kindPrimType || x == kindPrimConstraint -> True |
There was a problem hiding this comment.
The Constraint thing is a good point; I hadn't considered that classes have a different ‘most intuitive’ kind.
This || is correct because there's no way to make something Constraint-kinded that isn't a class right now, right? That is, something like
type IntState = MonadState Intcurrently isn't supported, and there isn't anything else like that which could create a Constraint other than a class?
I'd feel a tiny bit more comfortable if this || were instead conditional on the declaration type—a x == if isTypeClass d then kindPrimConstraint else kindPrimType sort of deal—because some day type synonyms for constraints might be a thing? But perhaps that's unnecessary future-proofing, if we know for sure that there aren't any Constraint loopholes in the present.
There was a problem hiding this comment.
That's a good suggestion - I think full constraint kinds (which includes being able to write type synonyms like your IntState one) is something that's likely to happen in the future, so I agree about making this conditional on the declaration type.
Yeah, that's something I wasn't able to get to this morning due to running out of time. |
|
Ok. Tests pass locally, and I believe I've addressed all comments. Let me know if there are any stylistic changes to make. |
|
Now I just need to write the changelog... |
|
Oh, and update the Pursuit page once this gets released. |
CHANGELOG.md
Outdated
| ``` | ||
|
|
||
| The docs will include the kind signature for `Foo`, but will | ||
| intentionally remove the kind signature for `Bar`, even if `Bar`'s |
There was a problem hiding this comment.
Ah! Ran out of time again. Thanks for pointing that out.
CHANGELOG.md
Outdated
|
|
||
| ```purescript | ||
| {- | ||
| data Foo :: (Type -> Type) -> Type -> Type -} |
There was a problem hiding this comment.
The compiler will infer forall k. (k -> Type) -> k -> Type for this data type, not (Type -> Type) -> Type -> Type.
There was a problem hiding this comment.
Thanks. I decided to adjust this example to use (f Int) rather than (f a)
CHANGELOG.md
Outdated
| `Type`. Thus, `Foo`'s inferred kind signature will be displayed | ||
| in its docs. | ||
|
|
||
| An "uninteresting" kind signature is one that follows this form: |
There was a problem hiding this comment.
I think we should say "kind" rather than "kind signature" here. A kind is something like Type, Type -> Type, or forall k. k -> Type. A kind signature is more than that: it's a declaration which tells you that a particular data type or type synonym or class has a particular kind, such as data Tuple :: Type -> Type -> Type.
There was a problem hiding this comment.
Mm... Makes sense. I've rewritten parts of the changelog entry to keep this in mind.
|
I rewrote the changelog entry to use this organization. I thought it better presented the new feature in a clearer way.
|
|
If this is good to merge, can I get an approval? |
|
Please don’t rush people. I would still like to see @rhendric’s suggestion about making the “uninteresting” check depend on what kind of declaration we have implemented, and I would like to think a bit more about how we present this in the release notes. |
|
Ah... Sorry about that. |
|
I think this changelog entry is a bit verbose. I don't think we should always provide examples of everything; that makes it difficult to quickly scan through a changelog to find what version a given change was made in. I think a more full description of how the feature works with examples to ensure that the reader understands would be better suited for the documentation repository. How about this instead: The compiler now displays kind signatures for data, newtype, type Both explicitly declared and inferred kinds are included in documentation. |
Works for me! |
|
I've added an issue to the docs repo, so we can add that page later. |
Description of the change
Fixes #4117.
Checklist:
Work done so far:
forall (k :: Type). k -> Typehas been simplified toforall k. k -> Type.Pending work
Type(decision pending)