@@ -37,8 +37,8 @@ simplicity, brevity and performance, albeit for some conversion overhead.
37
37
38
38
Let's formalize the above as a pair of types ` S ` and ` W ` .
39
39
40
- * Given a ` strong :: S ` , we can always turn it into a ` weak :: W ` .
41
- * Given a ` weak :: W ` , we can only turn it into a ` strong :: S ` if it passes
40
+ * given a ` strong :: S ` , we can always turn it into a ` weak :: W `
41
+ * given a ` weak :: W ` , we can only turn it into a ` strong :: S ` if it passes
42
42
all the checks
43
43
44
44
We can write these as pure functions.
@@ -57,8 +57,8 @@ useful enough pattern. Let's think of some strongweak pairs:
57
57
* `Word8 ` is a bounded natural number. `Natural ` can represent any natural
58
58
number. So `Natural ` is a weak type , which can be strengthened into `Word8 `
59
59
(or `Word16 `, `Word32 `, ... ) by asserting well- boundedness.
60
- * `[a]` doesn't have state any predicates. But we could weaken every `a` in
61
- the list. So `[a]` is a strong type , which can be weakened to `[Weak a]`.
60
+ * `[a]` doesn't state any predicates. But we could weaken every `a` in the
61
+ list. So `[a]` is a strong type , which can be weakened to `[Weak a]`.
62
62
* `NonEmpty a` * does* have a predicate. For useability and other reasons, we
63
63
only handle this predicate, and don't also weaken each `a` like above.
64
64
`NonEmpty a` weakens to `[a]`.
@@ -77,13 +77,11 @@ behaviour. The primary definitions are below:
77
77
78
78
```haskell
79
79
class Weaken a where
80
- type Weak a :: Type
80
+ type Weakened a :: Type
81
81
weaken :: a :: Weak a
82
82
83
- type Result = Validation Fails
84
- type Fails = NeAcc Fail
85
83
class Weaken a => Strengthen a where
86
- strengthen :: Weak a -> Result a
84
+ strengthen :: Weakened a -> Either Failure a
87
85
```
88
86
89
87
Note that a strong type may have only one associated weak type . The same weak
@@ -140,6 +138,10 @@ strengthening may fail while weakening cannot. For safe conversion enumeration
140
138
via typeclasses, consider Taylor Fausak's
141
139
[witch](https:// hackage. haskell. org/ package/ witch) library.
142
140
141
+ ### Not a generic `coerce`
142
+ strongweak isn't intended for automatic `coerce` ing between pairs of types.
143
+ For that, check out `gcoerce` at Lysxia's generic- data package.
144
+
143
145
### Not particularly speedy
144
146
The emphasis is on safety, which may come at the detriment of performance:
145
147
0 commit comments