-
Notifications
You must be signed in to change notification settings - Fork 70
Add documentation and examples for GHC-59692: Duplicate Instances #541
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d518449
Added documentation and examples for GHC-59692: Duplicate Instances
Qbxs 3fd3b49
CR-59692 DuplicatInstances Changed Wording & module name and added de…
Qbxs 98a3600
Remove empty line
Qbxs 4502947
Apply suggestions from code review
BinderDavid d626323
Add newlines at end of file
BinderDavid 46856a4
Update message-index/messages/GHC-59692/multipleInstances/index.md
BinderDavid 01a6edb
Add newlines
BinderDavid 095201e
Add newline
BinderDavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
--- | ||
title: Duplicate Instances | ||
summary: Multiple instances defined for the same type class and type. | ||
severity: error | ||
introduced: 9.6.1 | ||
--- | ||
|
||
For type class coherence, at most one instance may be defined for each type for the same type class. | ||
|
||
Identical instances should simply be removed. | ||
If multiple instances for the same type are required, circumventing this restriction is possible by introducing a `newtype` wrapper. |
11 changes: 11 additions & 0 deletions
11
message-index/messages/GHC-59692/multipleInstances/after/MultipleInstances.hs
This file contains hidden or 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,11 @@ | ||
module MultipleInstances where | ||
|
||
newtype Sum = Sum { getSum :: Int } | ||
|
||
instance Semigroup Sum where | ||
(<>) x y = Sum (getSum x + getSum y) | ||
|
||
newtype Product = Product { getProduct :: Int } | ||
|
||
instance Semigroup Product where | ||
(<>) x y = Product (getProduct x * getProduct y) |
7 changes: 7 additions & 0 deletions
7
message-index/messages/GHC-59692/multipleInstances/before/MultipleInstances.hs
This file contains hidden or 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,7 @@ | ||
module MultipleInstances where | ||
|
||
instance Semigroup Int where | ||
(<>) = (+) | ||
|
||
instance Semigroup Int where | ||
(<>) = (*) |
This file contains hidden or 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 @@ | ||
--- | ||
title: Multiple Instances for Semigroup Int | ||
--- | ||
|
||
It is not possible to give two definitions for `Semigroup Int`, one for the semigroup given by addition and one for the semigroup given by multiplication. | ||
If we require both instances, then we should define two `newtype` wrappers for `Int`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.