-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from haskellfoundation/ghc-93557-ghc-54540
Document GHC-54540 and GHC-93557
- Loading branch information
Showing
8 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-54540/constructorsNotInScope/after/ConstructorsNotInScope.hs
This file contains 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,6 @@ | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
module ConstructorsNotInScope where | ||
|
||
import System.IO( Handle ) | ||
|
||
-- It is not possible to derive an instance for the type class in this module. |
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-54540/constructorsNotInScope/before/ConstructorsNotInScope.hs
This file contains 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,6 @@ | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
module ConstructorsNotInScope where | ||
|
||
import System.IO( Handle ) | ||
|
||
deriving instance Eq Handle |
16 changes: 16 additions & 0 deletions
16
message-index/messages/GHC-54540/constructorsNotInScope/index.md
This file contains 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,16 @@ | ||
--- | ||
title: Cannot derive an instance for an abstract type | ||
--- | ||
|
||
The `Handle` type is abstract and does not export its constructors. It is therefore not possible to derive an instance of a typeclass for the `Handle` type in another module. You can only derive an instance of a typeclass in the module where `Handle` is defined. | ||
|
||
```` | ||
messages/GHC-54540/constructorsNotInScope/before/ConstructorsNotInScope.hs:6:1: error: [GHC-54540] | ||
• Can't make a derived instance of ‘Eq Handle’: | ||
The data constructors of ‘Handle’ are not all in scope | ||
so you cannot derive an instance for it | ||
• In the stand-alone deriving instance for ‘Eq Handle’ | ||
| | ||
6 | deriving instance Eq Handle | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
``` |
This file contains 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,8 @@ | ||
--- | ||
title: Cannot derive instance without constructors in scope | ||
summary: It is not possible to derive a typeclass instance if the constructors of the type are not in scope | ||
severity: error | ||
introduced: 9.6.1 | ||
--- | ||
|
||
Deriving an instance of a typeclass for a type is only possible if the constructors of the type are in scope at the point where you want to derive the instance. |
10 changes: 10 additions & 0 deletions
10
message-index/messages/GHC-93557/illegalSynonymInstance/after/IllegalSynonymInstance.hs
This file contains 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,10 @@ | ||
{-# LANGUAGE Haskell2010 #-} | ||
module IllegalSynonymInstance where | ||
|
||
data RGB = R | G | B | ||
|
||
instance Eq RGB where | ||
R == R = True | ||
G == G = True | ||
B == B = True | ||
_ == _ = False |
12 changes: 12 additions & 0 deletions
12
message-index/messages/GHC-93557/illegalSynonymInstance/before/IllegalSynonymInstance.hs
This file contains 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,12 @@ | ||
{-# LANGUAGE Haskell2010 #-} | ||
module IllegalSynonymInstance where | ||
|
||
data RGB = R | G | B | ||
|
||
type T = RGB | ||
|
||
instance Eq T where | ||
R == R = True | ||
G == G = True | ||
B == B = True | ||
_ == _ = False |
19 changes: 19 additions & 0 deletions
19
message-index/messages/GHC-93557/illegalSynonymInstance/index.md
This file contains 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,19 @@ | ||
--- | ||
title: Cannot implement a typeclass for type synonyms by default | ||
--- | ||
|
||
The programmer defined a data type `RGB`, and a type synonym `T`, and then tried to implement an instance of the type class `Eq` for `T`. | ||
In the language version Haskell 2010 this is not allowed, since all type class instances have to start with a type constructor. | ||
This problem can be fixed by implementing the typeclass instance directly for the type `RGB` instead of the type synonym `T`. | ||
|
||
``` | ||
messages/GHC-93557/illegalSynonymInstance/before/IllegalSynonymInstance.hs:8:10: error: [GHC-93557] | ||
• Illegal instance declaration for ‘Eq T’: | ||
All instance types must be of the form (T t1 ... tn) | ||
where T is not a synonym. | ||
• In the instance declaration for ‘Eq T’ | ||
Suggested fix: Perhaps you intended to use TypeSynonymInstances | ||
| | ||
8 | instance Eq T where | ||
| ^^^^ | ||
``` |
This file contains 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,16 @@ | ||
--- | ||
title: Illegal typeclass instance | ||
summary: Illegal typeclass instance | ||
severity: error | ||
introduced: 9.8.1 | ||
--- | ||
|
||
Using the language version Haskell 2010, only certain types are allowed as instances of a type class. | ||
Every type class instance in Haskell 2010 has the following form: | ||
``` | ||
instance C t where | ||
```` | ||
Here, `C` is the name of a type class, such as `Eq`, `Show`, `Read` or `Functor`, and `t` is a type. | ||
But only a subset of types `t` is allowed to appear in typeclass instances. | ||
These types must all have the form `T` or `T a ... b`, where `T` has to be the name of a type introduced by a data or newtype declaration, and the arguments `a` to `b` all have to be type variables. | ||
For example, `Maybe a` is allowed as a type in an instance, because the data type `Maybe` instantiates `T` and `a` is a type variable`, but `Maybe Int` is not allowed, since `Int` is not a type variable. |