Skip to content

Display inferred kind signatures in HTML docs#4119

Merged
JordanMartinez merged 17 commits intopurescript:masterfrom
JordanMartinez:insertInferredKindSigsIntoDocs
Jun 26, 2021
Merged

Display inferred kind signatures in HTML docs#4119
JordanMartinez merged 17 commits intopurescript:masterfrom
JordanMartinez:insertInferredKindSigsIntoDocs

Conversation

@JordanMartinez
Copy link
Copy Markdown
Contributor

@JordanMartinez JordanMartinez commented Jun 22, 2021

Description of the change

Fixes #4117.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

Work done so far:

  • The forall (k :: Type). k -> Type has been simplified to forall k. k -> Type.

Pending work

  • whether to display inferred kind signatures if all type parameters' kinds are Type (decision pending)
  • updating the changelog

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

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

@hdgarrood hdgarrood Jun 22, 2021

Choose a reason for hiding this comment

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

How about calling this function isUninteresting and saying that an "uninteresting" kind is a kind of the form:

  • Type
  • Constraint
  • Type -> K where K is uninteresting.

I think that makes it clearer which kinds are included, and I think it will make the code a little easier to read.

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.

Ah, thanks! That's a much better name.

@hdgarrood
Copy link
Copy Markdown
Contributor

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?)

Comment on lines +787 to +789
, 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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As the failed build shows, these expectations should be changed to have the correct keywords.

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.

Ha! Whoops!

P.TypeApp _ t1 t2 | t1 == kindFunctionType ->
isFunctionTypeStarTerminal t2
x
| x == kindPrimType || x == kindPrimConstraint -> True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 Int

currently 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.

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.

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.

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.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

I think the only thing left to change is to additionally hide uninteresting kinds which are explicitly declared

Yeah, that's something I wasn't able to get to this morning due to running out of time.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Ok. Tests pass locally, and I believe I've addressed all comments. Let me know if there are any stylistic changes to make.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Now I just need to write the changelog...

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

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

Choose a reason for hiding this comment

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

Bar or Tuple?

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.

Ah! Ran out of time again. Thanks for pointing that out.

CHANGELOG.md Outdated

```purescript
{-
data Foo :: (Type -> Type) -> Type -> Type -}
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.

The compiler will infer forall k. (k -> Type) -> k -> Type for this data type, not (Type -> Type) -> Type -> Type.

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.

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:
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.

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.

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.

Mm... Makes sense. I've rewritten parts of the changelog entry to keep this in mind.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

I rewrote the changelog entry to use this organization. I thought it better presented the new feature in a clearer way.

  • kind signatures weren't displayed
  • kind signatures are now displayed (except those with 'uninteresting' kinds)
  • inferred kind signatures are used when explicit ones aren't provided
  • kind signatures with 'uninteresting' kinds (both explicit and inferred) are not displayed

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

If this is good to merge, can I get an approval?

@hdgarrood
Copy link
Copy Markdown
Contributor

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.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Ah... Sorry about that.

@hdgarrood
Copy link
Copy Markdown
Contributor

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
synonym, and type class declarations in generated documentation. The
compiler now also includes documentation-comments (i.e. those which start
with a | character) both above and below the associated kind signature
declaration (if any) in generated documentation, whereas previously
documentation-comments above a kind signature declaration were ignored.

Both explicitly declared and inferred kinds are included in documentation.
The compiler omits including a kind signature in generated documentation
only when the kind is considered "uninteresting". An uninteresting kind is
defined as one where all of the declaration's type parameters have kind
Type.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

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.

Works for me!

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

I've added an issue to the docs repo, so we can add that page later.

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.

Include inferred kind signatures in HTML docs when no kind signature declaration is provided explicitly

3 participants