-
Notifications
You must be signed in to change notification settings - Fork 70
document GHC-59738 #500
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
Merged
BinderDavid
merged 3 commits into
haskellfoundation:main
from
MangoIV:mangoiv/ghc-59738
Oct 13, 2024
Merged
document GHC-59738 #500
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Scoped type variables only appears non-injectively in declaration header | ||
summary: a data declaration has a kind signature, where the implictly bound type variables cannot be matched up unambiguosly with the ones from the signature itself | ||
severity: error | ||
introduced: 9.6.4 | ||
--- | ||
|
||
The disconnected type variables error applies when kind-checking the header of a type/class declaration that has a | ||
separate, standalone kind signature. | ||
|
||
For this consider: | ||
|
||
```haskell | ||
type S a = Type | ||
|
||
type C :: forall k. S k -> Constraint | ||
class C (a :: S kk) where | ||
op :: .. kk .. | ||
``` | ||
|
||
Note that the class has a separate kind signature, so the elaborated decl should | ||
look like | ||
|
||
```haskell | ||
class C @kk (a :: S kk) where .. | ||
``` | ||
|
||
But how can we "connect up" the scoped variable `kk` with the skolem kind from the | ||
standalone kind signature for `C`? In general we do this by unifying the two. | ||
For example | ||
|
||
```haskell | ||
type T k = (k,Type) | ||
type W :: forall k. T k -> Type | ||
data W (a :: (x,Type)) = .. | ||
``` | ||
|
||
When we encounter `(a :: (x,Type))` we unify the kind `(x,Type)` with the kind `(T k)` | ||
from the standalone kind signature. Of course, unification looks through synonyms | ||
so we end up with the mapping `[x :-> k]` that connects the scoped type variable `x` | ||
with the kind from the signature. | ||
|
||
But in our earlier example this unification is ineffective, because `S` is a | ||
phantom synonym (and hence non-injective) that just discards its argument. So our answer to this issue is: | ||
|
||
> if matchUpSigWithDecl fails to connect `kk` with `k`, by unification, | ||
> we give up and complain about a "disconnected" type variable. | ||
|
||
The fix is easy: just add an explicit `@kk` parameter to the declaration, to bind `kk` | ||
explicitly, rather than binding it implicitly via unification. | ||
|
||
More discussion can be found [at ghc issue #24083](https://gitlab.haskell.org/ghc/ghc/-/issues/24083). | ||
|
||
This text was adapted from [Simon Peyton Jones' note on disconnected type variable, please refer to this note for more technical insight](https://gitlab.haskell.org/ghc/ghc/-/blob/2eee65e1a4f441e99b79f3dc6e7d60492e4cad78/compiler/GHC/Tc/Gen/HsType.hs#L3092-3147). |
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.
Uh oh!
There was an error while loading. Please reload this page.