Suspicious program accepted by GHC
Given:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module T where
data X a = X a
instance Eq (X Int) where
(X v :: X a) == X v' = v == v'
GHC 8.10.1 accepts this program without any complaint:
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.1
$ ghc a.hs
[1 of 1] Compiling T ( a.hs, a.o )
But the input is suspicious: The ascription X a
is more general than the definition given at X Int
.
Indeed, with GHC 8.4.2, I get a type error:
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.2
$ ghc a.hs
[1 of 1] Compiling T ( a.hs, a.o )
a.hs:9:4: error:
* Couldn't match type `a' with `Int'
Expected type: X Int
Actual type: X a
* When checking that the pattern signature: X a
fits the type of its context: X Int
In the pattern: X v :: X a
In an equation for `==': (X v :: X a) == X v' = v == v'
|
9 | (X v :: X a) == X v' = v == v'
| ^^^^^^^^^^
I'm not sure which version of GHC started accepting this program, I only have access to 8.4.2 and 8.10.1.
It seems to me like 8.4.2 is rightfully complaining here, while GHC 8.10.1 is erroneously accepting the program. Is this change in behavior expected?