Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic explanation of 59692 #534

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions message-index/messages/GHC-59692/example1/after/Example1.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Example1 where

data T a

instance Eq a => Eq (T a) where
(==) = (==)
9 changes: 9 additions & 0 deletions message-index/messages/GHC-59692/example1/before/Example1.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Example1 where

data T a

instance Eq a => Eq (T a) where
(==) = (==)

instance Show a => Eq (T a) where
(==) = (==)
15 changes: 15 additions & 0 deletions message-index/messages/GHC-59692/example1/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Even though the instances have different constraints, they are still considered the same.

## Error message

```
messages/GHC-59692/example1/before/Example1.hs:3:10: error: [GHC-59692]
Duplicate instance declarations:
instance Eq a => Eq (T a)
-- Defined at messages/GHC-59692/example1/before/Example1.hs:3:10
instance Show a => Eq (T a)
-- Defined at messages/GHC-59692/example1/before/Example1.hs:6:10
|
3 | instance Eq a => Eq (T a) where
| ^^^^^^^^^^^^^^^^
```
10 changes: 10 additions & 0 deletions message-index/messages/GHC-59692/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Duplicate instance declarations
summary: An instance has been defined twice for the same type.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessarily exactly twice, is it? A more precise way to describe this would be, perhaps:

Suggested change
summary: An instance has been defined twice for the same type.
summary: An instance of a class has been defined once again for the same type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"once again" makes it sound like there was an instance in the past and now there is one once again. Perhaps just "multiple times" instead of "twice" then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for the compiler, there was an instance that it saw in the past, only it's very close past: maybe in the same .hs file (but maybe not). So, I don't see a problem here. But "multiple times" works for me too.

introduced: 9.6.1
severity: error
---

You can only define a single instance for every type, because it must be possible to automatically resolve class constraints without any ambiguity.
Note that instances are considered the same even if they have different constraints. Only the arguments of the class are considered when matching instances.
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.
Loading