... | ... | @@ -55,6 +55,31 @@ GHC now implements [proposal #371](https://github.com/ghc-proposals/ghc-proposal |
|
|
* 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`.
|
|
|
|
|
|
### 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:
|
|
|
|
|
|
```haskell
|
|
|
class C a b | a -> b where
|
|
|
op :: a -> b -> ()
|
|
|
|
|
|
f x = op True x
|
|
|
```
|
|
|
|
|
|
Previously, GHC would infer `f :: forall b. C Bool b => b -> ()`. However, the functional dependency says that only one type could ever be used for `b`: this function is hardly valid "for all" `b` s. GHC 9.4 will reject this program, looking for the (non-existent) instance for `C Bool b`:
|
|
|
|
|
|
```plaintext
|
|
|
error:
|
|
|
• No instance for (C Bool b0) arising from a use of ‘op’
|
|
|
• In the expression: op True x
|
|
|
In an equation for ‘f’: f x = op True x
|
|
|
|
|
|
|
8 | f x = op True x
|
|
|
| ^^
|
|
|
```
|
|
|
|
|
|
If you want to retain the old behavior, add a (backward-compatible) type signature to `f`, explicitly requesting this unusual quantification.
|
|
|
|
|
|
### Removal of derived constraints
|
|
|
|
|
|
When GHC's typechecker tries to solve constraints, it can generate new derived constraints. For example, if we have a class with a functional dependency `C a b | a -> b`, if we have evidence for the two constraints `C a b1`, `C a b2` we can derive the equality constraint `b1 ~ b2`. GHC used to represent these derived constraints in a special form, but now they are normal Wanted constraints.
|
... | ... | @@ -128,31 +153,6 @@ 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:
|
|
|
|
|
|
```haskell
|
|
|
class C a b | a -> b where
|
|
|
op :: a -> b -> ()
|
|
|
|
|
|
f x = op True x
|
|
|
```
|
|
|
|
|
|
Previously, GHC would infer `f :: forall b. C Bool b => b -> ()`. However, the functional dependency says that only one type could ever be used for `b`: this function is hardly valid "for all" `b` s. GHC 9.4 will reject this program, looking for the (non-existent) instance for `C Bool b`:
|
|
|
|
|
|
```plaintext
|
|
|
error:
|
|
|
• No instance for (C Bool b0) arising from a use of ‘op’
|
|
|
• In the expression: op True x
|
|
|
In an equation for ‘f’: f x = op True x
|
|
|
|
|
|
|
8 | f x = op True x
|
|
|
| ^^
|
|
|
```
|
|
|
|
|
|
If you want to retain the old behavior, add a (backward-compatible) type signature to `f`, explicitly requesting this unusual quantification.
|
|
|
|
|
|
#### 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.
|
... | ... | |