You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
summary: Multiple instances defined for the same type class and type.
4
-
severity: error
5
4
introduced: 9.6.1
5
+
severity: error
6
6
---
7
7
8
-
For type class coherence, at most one instance may be defined for each type for the same type class.
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
+
10
+
If the instances are identical, you should simply remove one.
11
+
If you want multiple instances for the same type, you can circumvent this restriction by introducing a `newtype` wrapper. An example of this is shown in the solution for the "Multiple Instances for Semigroup Int" example.
12
+
13
+
Note that instances are considered the same even if they have different constraints. Only the arguments of the class are considered when matching instances. This issue is shown in the "Identical Instance Heads" example.
9
14
10
-
Identical instances should simply be removed.
11
-
If multiple instances for the same type are required, circumventing this restriction is possible by introducing a `newtype` wrapper.
15
+
See the [GHC User Guide](https://downloads.haskell.org/~ghc/9.12.1/docs/users_guide/exts/instances.html) for more information on instance declarations and resolution.
0 commit comments