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 Fails
- strengthenBounded :: forall m n. (Typeable n, Integral n, Show n, Typeable m, Integral m, Show m, Bounded m) => n -> Result m
- type Fails = NeAcc Fail
- data Fail
- prettyFail :: Fail -> Text
- fail1 :: Fail -> Result a
- failOther :: [Text] -> Result a
- failShow :: forall s w. (Typeable w, Show w, Typeable s) => w -> [Text] -> Result s
- maybeFailShow :: forall a. (Typeable (Weak a), Typeable a) => [Text] -> Maybe a -> 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 Fails Source #
Helpers
strengthenBounded :: forall m n. (Typeable n, Integral n, Show n, Typeable m, Integral m, Show m, Bounded m) => n -> Result m Source #
Strengthen one numeric type into another.
n
must be "wider" than m
.
Strengthen failures
A failure encountered during strengthening.
FailShow | A failure containing lots of detail. Use in concrete instances where you
already have the |
FailOther | A failure. Use in abstract instances to avoid heavy contexts. (Remember that generic strengtheners should wrap these nicely anyway!) |
| |
FailField | Some failures occurred when strengthening from one data type to another. Field indices are from 0 in the respective constructor. Field names are provided if are present in the type. This is primarily intended to be used by generic strengtheners. |
prettyFail :: Fail -> Text Source #
Helpers
maybeFailShow :: forall a. (Typeable (Weak a), Typeable a) => [Text] -> Maybe a -> Result a Source #
Re-exports
type family Weak a :: Type Source #
The weakened type for some type.