-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clarify instance design; add more decomposers
- Loading branch information
Showing
4 changed files
with
182 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,7 +1,35 @@ | ||
module Strongweak | ||
( module Strongweak.Weaken | ||
( | ||
-- * Instance design | ||
-- $strongweak-instance-design | ||
|
||
-- * Re-exports | ||
module Strongweak.Weaken | ||
, module Strongweak.Strengthen | ||
) where | ||
|
||
import Strongweak.Weaken | ||
import Strongweak.Strengthen | ||
|
||
{- $strongweak-instance-design | ||
We identify two distinct types of instances for strongweak classes: | ||
* /invariant handler:/ removes or adds an invariant | ||
* /decomposer:/ transforms through some structural type | ||
In order to provide good behaviour and composability, we don't mix both in a | ||
single instance. The decomposers are really just convenience to ease instance | ||
derivation. In general, decomposers will have a recursive context, and invariant | ||
handlers won't. | ||
An example is @'Data.List.NonEmpty.NonEmpty' a@. We could weaken this to @[a]@, | ||
but also to @['Weak' a]@. However, the latter would mean decomposing and | ||
removing an invariant simultaneously. It would be two separate strengthens in | ||
one instance. And now, your 'a' must be in the strongweak ecosystem, which isn't | ||
necessarily what you want - indeed, it appears this sort of design would require | ||
a @'Weak' a = a, weaken = id@ overlapping instance, which I do not want. On the | ||
other hand, @[a]@ /does/ weaken to @['Weak' a]@, because there are no invariants | ||
present to remove, so decomposing is all the user could hope to do. | ||
-} |
This file contains 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
This file contains 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
This file contains 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