Omit kind sigs where kind is uninteresting, even when parens are involved#4137
Omit kind sigs where kind is uninteresting, even when parens are involved#4137JordanMartinez merged 17 commits intopurescript:masterfrom JordanMartinez:fixUninterestingKindsWhenParensIncluded
Conversation
kl0tl
left a comment
There was a problem hiding this comment.
Should we also drop sorts annotations from developper written kinds?
| isUninteresting keyword = \case | ||
| P.TypeApp _ t1 t2 | t1 == kindFunctionType -> | ||
| -- `Type -> ...` | ||
| P.TypeApp _ (P.TypeApp _ (P.TypeConstructor () Prim.Function) ty) t2 | isKindPrimType ty -> |
There was a problem hiding this comment.
We need to account for the case where an application is wrapped in parens, like (Type -> Type), otherwise we deem such kinds interesting and they show up in the generated docs.
There was a problem hiding this comment.
Meaning if we have something like this?
data Foo :: (Type -> Type)
data Foo a = Foo awhich is the same as writing the uninteresting kind signature below:
data Foo :: Type -> Type
data Foo a = Foo aThere was a problem hiding this comment.
Yeah exactly, data Foo :: (Type -> Type) should be treated like data Foo :: Type -> Type but the kind is currently documented.
There was a problem hiding this comment.
Wouldn't that mean accounting for various other situations, too? I'm starting to wonder if this is really worth doing and if we should instead say, "Yeah, just don't do that."
As examples of other things:
-- or any uninteresting kind where the whole thing is wrapped in parens
data Foo1 :: (Type -> Type -> Type)
data Foo1 a b = Foo1 a b
-- or any uninteresting kind where the the tail part is wrapped in parens
data Foo2 :: Type -> (Type -> Type)
data Foo2 a b = Foo2 a bThere was a problem hiding this comment.
Yes those kinds should be uninteresting too. It should only be a matter of adding a P.ParensInType _ ty -> isUninteresting ty case to isUninteresting though.
There was a problem hiding this comment.
Done and added tests for it. I haven't tested this locally.
There was a problem hiding this comment.
Does this cover data Foo :: (->) Type Type? Or data Foo :: ((->) Type) Type, or, for that matter, data Foo :: ((((->)) Type)) Type?
These are profoundly obnoxious edge cases, but if they cause problems, maybe the thing to do is just strip out all parens using a traversal before calling isUninteresting.
There was a problem hiding this comment.
Good question. I'll add a test for that.
There was a problem hiding this comment.
Latest commit adds these three tests, the latter two of which currently fail.
There was a problem hiding this comment.
Yeah, stripping those parenthesis out and then solving the problem with the original approach was much easier than trying to account for them at the same time.
|
Note: while I was working on this PR, I also learned that the parens situation will be displayed in the kind signature if it's included in an interesting kind signature. For example: data Foo :: forall k. k -> (Type)
data Foo a = Foowill be rendered as the above, not as below: data Foo :: forall k. k -> Type
data Foo a = FooI'm not sure whether it's really worth it to remove the parenthesis because I doubt this will happen in practice. |
Meaning, if the developer writes data Foo (a :: Type) = Foo athen we render the following? data Foo a = Foo a |
|
Just added a test for this. It passed but nothing changed in my code: |
That's still a kind annotation. I think a sort annotation would be the foreign import data DataSortAnnotation :: forall (k :: Type). k -> Type |
|
Mm... I'm not so sure. Harry said something about this that makes me think otherwise...? |
|
Changelog entry has been added now that #4132 is in. |
|
The changelog file name should start with |
|
This PR should be ready for another review when someone has a moment. |
There was a problem hiding this comment.
I still think we should render
foreign import data DataSortAnnotation :: forall (k :: Type). k -> Typeas
foreign import data DataSortAnnotation :: forall k. k -> Type
for consistency with inferred kinds, but that’s not really related to this pull request so it can happen in another one (and perhaps it should rather be done by a formatter). Ditto for extraneous parens in interesting kinds.
This looks great though, thank you!
This doesn’t seem to be the case: on 73ff5f6 we render for foreign import data DataSortAnnotation :: forall (k :: Type). k -> Typebecause we only drop sort annotations for inferred kinds. |
|
Gotcha. I've reported this as a bug in #4160 |

Description of the change
Fixes #4136
Checklist: