... | ... | @@ -55,9 +55,11 @@ The use of `(~)` now requires `TypeOperators` instead of `GADTs` or `TypeFamilie |
|
|
* If `(~)` is used but `TypeOperators` is not enabled, GHC will produce a `-Wtype-equality-requires-operators` warning. This warning can be fixed by enabling `TypeOperators`.
|
|
|
* If `(~)` is used but is not imported transitively via `Data.Type.Equality` or `Prelude`, GHC will produce a `-Wtype-equality-out-of-scope` warning. This warning can be fixed by either importing one of these modules or, in the case where a custom `Prelude` is being used, re-exporting `(~)` from the custom `Prelude`.
|
|
|
|
|
|
### Type inference changes involving simplifiable constraints
|
|
|
### Type inference changes for local bindings with simplifiable constraints
|
|
|
|
|
|
GHC 9.4 is more eager to simplify constraints in certain situations, which can have user-facing ramifications. Here is an example of a program that will no longer typecheck in 9.4 (but would typecheck in earlier versions):
|
|
|
GHC can sometimes infer more restrictive type signatures in situations where a local binding without a type signature requires simplifiable constraints.
|
|
|
|
|
|
For example, the following program no longer typechecks in GHC 9.4:
|
|
|
|
|
|
```haskell
|
|
|
type family F x
|
... | ... | @@ -71,7 +73,7 @@ g = go |
|
|
go = f
|
|
|
```
|
|
|
|
|
|
GHC 9.4 will give `go` the type `(F a ~ Maybe a, Show a) => a -> IO ()`, as it will rewrite `Show (F a)` to `Show (Maybe a)` and then use the top-level `Show` instance for `Maybe` to simplify `Show (Maybe a)` to `Show a`. This causes a type error when trying to typecheck `g = go`, as `g` is unable to satisfy `go`'s `Show a` constraint:
|
|
|
The problem is that the `Show (F a)` constraint simplifies to `Show a` (using `F a ~ Maybe a` and the top-level `Show` instance for `Maybe`), so GHC wants to infer a type for `go` which includes the constraint `Show a`, causing the following error:
|
|
|
|
|
|
```plaintext
|
|
|
error:
|
... | ... | @@ -93,29 +95,6 @@ g = go |
|
|
go = f
|
|
|
```
|
|
|
|
|
|
A similar situation arises in this program:
|
|
|
|
|
|
```hs
|
|
|
type family F x
|
|
|
|
|
|
class C a b | b -> a
|
|
|
|
|
|
class C (F b) b => D b
|
|
|
|
|
|
f :: (C () b, D b) => Maybe b
|
|
|
f = g
|
|
|
|
|
|
g :: (C a b) => Maybe b
|
|
|
g = Nothing
|
|
|
```
|
|
|
|
|
|
GHC 9.4 will fail to compile this program because since it will not infer `F b ~ ()`. To make this compile with 9.4 or later, add that as an explicit constraint:
|
|
|
|
|
|
```hs
|
|
|
f :: (C () b, D b, F b ~ ()) => Maybe b
|
|
|
f = g
|
|
|
```
|
|
|
|
|
|
### No generalization over type variables determined by functional dependencies
|
|
|
|
|
|
A small change has been made to the way GHC infers types for definitions with no type signature: GHC will no longer generalize a function over a type variable determined by a functional dependency. For example:
|
... | ... | @@ -141,6 +120,29 @@ error: |
|
|
|
|
|
If you want to retain the old behavior, add a (backward-compatible) type signature to `f`, explicitly requesting this unusual quantification.
|
|
|
|
|
|
A similar situation arises in this program:
|
|
|
|
|
|
```hs
|
|
|
type family F x
|
|
|
|
|
|
class C a b | b -> a
|
|
|
|
|
|
class C (F b) b => D b
|
|
|
|
|
|
f :: (C () b, D b) => Maybe b
|
|
|
f = g
|
|
|
|
|
|
g :: (C a b) => Maybe b
|
|
|
g = Nothing
|
|
|
```
|
|
|
|
|
|
GHC 9.4 will fail to compile this program because since it will not infer `F b ~ ()`. To make this compile with 9.4 or later, add that as an explicit constraint:
|
|
|
|
|
|
```hs
|
|
|
f :: (C () b, D b, F b ~ ()) => Maybe b
|
|
|
f = g
|
|
|
```
|
|
|
|
|
|
### GHC rejects ambiguous situations when solving for injective type families
|
|
|
|
|
|
There were previously cases around functional dependencies and injective type families where the result of type inference would depend on the order of constraints, as written in a source file. These cases are fundamentally ambiguous. While GHC previously made an arbitrary decision, it now notices the ambiguity and rejects the program.
|
... | ... | |