Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- module Strongweak.Weaken
- module Strongweak.Strengthen
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
. We could weaken this to NonEmpty
a[a]
,
but also to [
. However, the latter would mean decomposing and
removing an invariant simultaneously. It would be two separate strengthens in
one instance. And now, your Weaken
a]a
must be in the strongweak ecosystem, which isn't
necessarily what you want - indeed, it appears this sort of design would require
a
overlapping instance, which I do not want. On the
other hand, Weaken
a = a, weaken = id[a]
does weaken to [
, because there are no invariants
present to remove, so decomposing is all the user could hope to do.Weaken
a]
Re-exports
module Strongweak.Weaken
module Strongweak.Strengthen