Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- type (:|) e es = Member e es
- class KnownPrefix (es :: [Type]) where
- prefixLength :: Int
- type family Length (xs :: [k]) :: Nat where ...
- class KnownPrefix es => Subset (xs :: [Type]) (es :: [Type]) where
- subsetFullyKnown :: Bool
- morph' :: Vary xs -> Vary ys
- type Index (n :: Nat) (l :: [k]) = Type_List_Too_Vague___Please_Specify_Prefix_Of_List_Including_The_Desired_Type's_Location n l l
- type IndexOf (x :: k) (xs :: [k]) = IndexOf' (MaybeIndexOf x xs) x xs
- type Mappable a b xs ys = (a :| xs, b :| ys, ys ~ Mapped a b xs)
- pop :: Vary (a : as) -> Either (Vary as) a
- size :: forall xs. KnownNat (Length xs) => Vary xs -> Word
- activeIndex :: Vary a -> Word
- natValue :: forall (n :: Nat) a. (KnownNat n, Num a) => a
Useful in generic code
type (:|) e es = Member e es Source #
Constrain es
to be any type list containing e
.
Useful to talk about variants generically without having to specify the exact type list right away.
For instance, the type of from
is
Vary.from :: (a :| l) => a -> Vary l
because we can use it to construct any Vary as long as there is an a
somewhere in its list of types.
class KnownPrefix (es :: [Type]) where Source #
Calculate length of a statically known prefix of es
.
prefixLength :: Int Source #
Instances
KnownPrefix es Source # | |
Defined in Vary.Utils prefixLength :: Int Source # | |
KnownPrefix es => KnownPrefix (e ': es) Source # | |
Defined in Vary.Utils prefixLength :: Int Source # |
class KnownPrefix es => Subset (xs :: [Type]) (es :: [Type]) where Source #
Provide evidence that xs
is a subset of es
.
Nothing
type Index (n :: Nat) (l :: [k]) = Type_List_Too_Vague___Please_Specify_Prefix_Of_List_Including_The_Desired_Type's_Location n l l Source #
Indexed access into the list
type IndexOf (x :: k) (xs :: [k]) = IndexOf' (MaybeIndexOf x xs) x xs Source #
Get the first index of a type
type Mappable a b xs ys = (a :| xs, b :| ys, ys ~ Mapped a b xs) Source #
Constraint to link the input and output lists together, without specifying any particular element order.
This allows us to defer type signatures until the final place the variant is used.
pop :: Vary (a : as) -> Either (Vary as) a Source #
Attempts to extract a value of the first type from the Vary
.
If this failed, we know it has to be one of the other possibilities.
This function can also be seen as turning one layer of Vary
into its isomorphic Either
representation.
This function is not often useful in normal
code, but super useful in generic code where you want to recurse on the variant's types.
For instance when implementing a typeclass for any Vary
whose elements implement the typeclass:
instance Show (Vary '[]) where show = Vary.exhaustiveCase instance (Show a, Show (Vary as)) => Show (Vary (a : as)) where show vary = case Vary.pop vary of Right val -> "Vary.from " <> show val Left other -> show other
To go the other way:
Informational
size :: forall xs. KnownNat (Length xs) => Vary xs -> Word Source #
Returns the number of elements contained in this variant.
Does not actually use the runtime representation of the variant in any way.
activeIndex :: Vary a -> Word Source #
Returns the currently active 'tag index' of the variant.
Not useful in normal code, but maybe nice in certaing debugging scenarios.
Note that this index changes whenever a variant is morph
ed.