Skip to content

Commit 7de6d28

Browse files
noughtmareslotThe
authored andcommitted
Basic explanation of 59692
1 parent 6b513c8 commit 7de6d28

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Example1 where
2+
3+
data T a
4+
5+
instance Eq a => Eq (T a) where
6+
(==) = (==)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Example1 where
2+
3+
data T a
4+
5+
instance Eq a => Eq (T a) where
6+
(==) = (==)
7+
8+
instance Show a => Eq (T a) where
9+
(==) = (==)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Even though the instances have different constraints, they are still considered the same.
2+
3+
## Error message
4+
5+
```
6+
messages/GHC-59692/example1/before/Example1.hs:3:10: error: [GHC-59692]
7+
Duplicate instance declarations:
8+
instance Eq a => Eq (T a)
9+
-- Defined at messages/GHC-59692/example1/before/Example1.hs:3:10
10+
instance Show a => Eq (T a)
11+
-- Defined at messages/GHC-59692/example1/before/Example1.hs:6:10
12+
|
13+
3 | instance Eq a => Eq (T a) where
14+
| ^^^^^^^^^^^^^^^^
15+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Duplicate instance declarations
3+
summary: An instance has been defined twice for the same type.
4+
introduced: 9.6.1
5+
severity: error
6+
---
7+
8+
You can only define a single instance for every type, because it must be possible to automatically resolve class constraints without any ambiguity.
9+
Note that instances are considered the same even if they have different constraints. Only the arguments of the class are considered when matching instances.
10+
See the [GHC User Guide](https://downloads.haskell.org/~ghc/9.10.1/docs/users_guide/exts/instances.html) for more information on instance declarations and resolution.

0 commit comments

Comments
 (0)