Skip to content

Commit d83e897

Browse files
QbxsBinderDavid
authored andcommitted
Added documentation and examples for GHC-59692: Duplicate Instances
1 parent 9e1acd3 commit d83e897

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module DivergingInstances where
2+
3+
newtype Sum = Sum { getSum :: Int }
4+
5+
instance Semigroup Sum where
6+
(<>) x y = Sum (getSum x + getSum y)
7+
8+
newtype Product = Product { getProduct :: Int }
9+
10+
instance Semigroup Product where
11+
(<>) x y = Product (getProduct x * getProduct y)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module DivergingInstances where
2+
3+
instance Semigroup Int where
4+
(<>) = (+)
5+
6+
instance Semigroup Int where
7+
(<>) = (*)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Duplicate Instances
3+
summary: Multiple instances defined for the same type class and type.
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
For type class coherence, at most one instance may be defined for each type for the same type class.
9+
10+
Identical instances should simply be removed.
11+
If for the same type diverging instances are required, circumventing this restriction is possible by introducing a `newtype` wrapper.

0 commit comments

Comments
 (0)