Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Weaken
class
Transform an a
to a
.Weaken
a
A given strong type a
has exactly one associated weak type
.
Multiple strong types may weaken to the same weak type.Weaken
a
The following laws must hold:
Most instances should strip an invariant, and not have a recursive context. Some types don't have an invariant either handle an invariant, or decompose. See Strongweak for a discussion on this design.
Instances
Weaken Int16 Source # | |
Weaken Int32 Source # | |
Weaken Int64 Source # | |
Weaken Int8 Source # | |
Weaken Word16 Source # | |
Weaken Word32 Source # | |
Weaken Word64 Source # | |
Weaken Word8 Source # | |
Weaken (Identity a) Source # | Strip wrapper. |
Weaken (NonEmpty a) Source # | Weaken non-empty lists into plain lists. |
Weaken a => Weaken [a] Source # | Decomposer. Weaken every element in a list. |
(Weaken a, Weaken b) => Weaken (Either a b) Source # | Decomposer. Weaken either side of an |
(Weaken a, Weaken b) => Weaken (a, b) Source # | Decomposer. Weaken both elements of a tuple. |
Weaken (Const a b) Source # | Strip wrapper. |
Weaken (Refined p a) Source # | Strip refined type refinement. |
Vector v a => Weaken (Vector v n a) Source # | Weaken sized vectors into plain lists. |
liftWeakF :: Weaken a => (Weak a -> b) -> a -> b Source #
Lift a function on a weak type to the associated strong type.
SW
helper
Strength enumeration: is it strong, or weak?
Primarily interesting at the type level (using DataKinds).
type family SW (s :: Strength) a :: Type where ... Source #
Get either the strong or weak representation of a type, depending on the type-level "switch" provided.
This is intended to be used in data types that take a Strength
type. Define
your type using strong fields wrapped in SW s
. You then get the weak
representation for free, using the same definition.
data A (s :: Strength) = A { a1 :: SW s Word8 , a2 :: String }