Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give Compose's instances explicit kind signatures #607

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

RyanGlScott
Copy link
Collaborator

Previously, the promoted versions of certain Compose instances (Functor, Foldable, etc.) would be overly general due to the fact that singletons-th omits instance contexts during promotion. For example, the promoted Functor instance for Compose was:

instance PFunctor (Compose (f :: k -> Type) (g :: Type -> k)) where ...

But this was too general, as f and g should both be of kind Type -> Type instead. The defunctionalization symbols associated with the instances also had a similar problem.

This patch annotates each instance with an explicit kind (e.g., Functor (Compose (f :: Type -> Type) g) to ensure that the promoted instances also have the intended kind. This is very much in the same spirit as the situation described in Note [Using standalone kind signatures not present in the base library] in Control.Monad.Singletons.Internal, but for instance declarations instead of class declarations.

Resolves the "Overly polymorphic instance methods" section of #601.

@RyanGlScott RyanGlScott changed the title Give Compose's instances explicit kind signatures Give Compose's instances explicit kind signatures Jun 18, 2024
Previously, the promoted versions of certain `Compose` instances (`Functor`,
`Foldable`, etc.) would be overly general due to the fact that `singletons-th`
omits instance contexts during promotion. For example, the promoted `Functor`
instance for `Compose` was:

```hs
instance PFunctor (Compose (f :: k -> Type) (g :: Type -> k)) where ...
```

But this was too general, as `f` and `g` should both be of kind `Type -> Type`
instead. The defunctionalization symbols associated with the instances also had
a similar problem.

This patch annotates each instance with an explicit kind (e.g., `Functor
(Compose (f :: Type -> Type) g)` to ensure that the promoted instances also
have the intended kind. This is very much in the same spirit as the situation
described in `Note [Using standalone kind signatures not present in the base
library]` in `Control.Monad.Singletons.Internal`, but for instance declarations
instead of class declarations.

Resolves the "Overly polymorphic instance methods" section of #601.
@RyanGlScott RyanGlScott force-pushed the explicit-instance-kind-signatures branch from e328357 to b40498c Compare June 18, 2024 11:47
@RyanGlScott RyanGlScott merged commit f44bf07 into master Jun 19, 2024
24 checks passed
@RyanGlScott RyanGlScott deleted the explicit-instance-kind-signatures branch June 19, 2024 10:56
RyanGlScott added a commit that referenced this pull request Jun 30, 2024
This adds more explicit `Type -> Type` kind signatures to definitions that
would otherwise be kind-generalized to have overly polymorphic kinds:

* The kinds of `Asum` and `Msum` (the promoted counterparts to the term-level
  `asum` and `msum` functions, respectively).
* The helper type families generated when promoting the `Alternative` and
  `MonadPlus` instances for `Data.Functor.Product`. This sort of kind
  polymorphism isn't observable by users in today's GHC, but it will cause
  problems later in a future version of GHC that implements
  [GHC#23515](https://gitlab.haskell.org/ghc/ghc/-/issues/23515). (See #601.)

(I should have added these as part of #606 or #607, but I forgot them due to an
oversight.)
RyanGlScott added a commit that referenced this pull request Jul 1, 2024
This adds more explicit `Type -> Type` kind signatures to definitions that
would otherwise be kind-generalized to have overly polymorphic kinds:

* The kinds of `Asum` and `Msum` (the promoted counterparts to the term-level
  `asum` and `msum` functions, respectively).
* The helper type families generated when promoting the `Alternative` and
  `MonadPlus` instances for `Data.Functor.Product`. This sort of kind
  polymorphism isn't observable by users in today's GHC, but it will cause
  problems later in a future version of GHC that implements
  [GHC#23515](https://gitlab.haskell.org/ghc/ghc/-/issues/23515). (See #601.)

(I should have added these as part of #606 or #607, but I forgot them due to an
oversight.)
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.

1 participant