... | ... | @@ -9,7 +9,25 @@ This guide summarises the changes you may need to make to your code to migrate f |
|
|
|
|
|
## Compiler changes
|
|
|
|
|
|
TODO
|
|
|
### Kind inference for data family instances is pickier
|
|
|
|
|
|
GHC's kind inference for data/newtype instance declarations is slightly more restrictive than before. The new rule is this: in data/newtype instance declararations (unlike ordinary data/newtype declarations) we do *not* look at the constructor declarations when inferring the kind of the instance header. The principle is that *the instantiation of the data instance should be apparent from the header alone*.
|
|
|
|
|
|
A consequence of this change is that some programs that compiled on previous versions of GHC will no longer be accepted under 9.2. Here is such an example:
|
|
|
|
|
|
```hs
|
|
|
data family T :: k -> Type
|
|
|
data instance T a = MkT1 a
|
|
|
```
|
|
|
|
|
|
Previous versions of GHC would look at the `MkT1` constructor to infer that `a` has kind `Type` and accept the data instance. GHC 9.2, however, only looks of the header (`data instance T a`) and concludes that `a` has kind `k`. As a result, the `MkT1` constructor is ill kinded, so GHC will throw an `Expected a type, but ‘a’ has kind ‘k’` error.
|
|
|
|
|
|
The workaround is to simply make the kind of `a` explicit:
|
|
|
|
|
|
```hs
|
|
|
data family T :: k -> Type
|
|
|
data instance T (a :: Type) = MkT1 a
|
|
|
```
|
|
|
|
|
|
---
|
|
|
|
... | ... | |