Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- class Weaken a => Strengthen a where
- strengthen :: Weak a -> Result a
- restrengthen :: (Strengthen a, Weaken a) => a -> Result a
- type Result = Validation StrengthenFailure
- strengthenBounded :: forall m n. (Typeable n, Integral n, Show n, Typeable m, Integral m, Bounded m, FiniteBits m) => n -> Result m
- data StrengthenFailure = StrengthenFailure {}
- failStrengthen1 :: [Builder] -> Result a
- failStrengthen :: [Builder] -> [(Builder, StrengthenFailure)] -> Result a
- type family Weak a :: Type
Strengthen
class
class Weaken a => Strengthen a where Source #
Attempt to strengthen some
, asserting certain invariants.Weak
a
We take Weaken
as a superclass in order to maintain strong/weak type pair
consistency. We choose this dependency direction because we treat the strong
type as the "canonical" one, so Weaken
is the more natural (and
straightforward) class to define. That does mean the instances for this class
are a little confusingly worded. Alas.
See Strongweak for class design notes and laws.
strengthen :: Weak a -> Result a Source #
Attempt to strengthen some
to its associated strong type
Weak
aa
.
Instances
restrengthen :: (Strengthen a, Weaken a) => a -> Result a Source #
Weaken a strong value, then strengthen it again.
Potentially useful if you have previously used
unsafeStrengthen
and now wish to check the
invariants. For example:
>>>
restrengthen $ unsafeStrengthen @(Vector 2 Natural) [0]
Failure ...
type Result = Validation StrengthenFailure Source #
Helpers
strengthenBounded :: forall m n. (Typeable n, Integral n, Show n, Typeable m, Integral m, Bounded m, FiniteBits m) => n -> Result m Source #
Strengthen one numeric type into another.
n
must be "wider" than m
.
and FiniteBits
m
are for error printing. We're forced to
Show
n
because linear-text-builder can't print unbounded integrals. PR:
https://github.com/Bodigrim/linear-builder/pull/20Show
n
Strengthen failures
data StrengthenFailure Source #
A failure encountered during strengthening.
StrengthenFailure | |
|
Instances
Show StrengthenFailure Source # | |
Defined in Strongweak.Strengthen showsPrec :: Int -> StrengthenFailure -> ShowS # show :: StrengthenFailure -> String # showList :: [StrengthenFailure] -> ShowS # |
failStrengthen1 :: [Builder] -> Result a Source #
failStrengthen :: [Builder] -> [(Builder, StrengthenFailure)] -> Result a Source #
Re-exports
type family Weak a :: Type Source #
The weakened type for some type.