Copyright | (c) Samuel Schlesinger 2020 |
---|---|
License | MIT |
Maintainer | sgschlesinger@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Prod (xs :: [*])
- extract :: forall x xs. x `HasIndexIn` xs => Prod xs -> x
- index :: forall x xs. x `HasIndexIn` xs => Word
- tailN :: forall n xs. (KnownNat n, n <= Length xs) => Prod xs -> Prod (Tail n xs)
- initN :: forall n xs. (KnownNat n, n <= Length xs) => Prod xs -> Prod (Init n xs)
- dropFirst :: forall x xs. Prod (x ': xs) -> Prod xs
- class Consume xs where
- type family IndexIn (x :: k) (xs :: [k]) where ...
- class KnownNat (x `IndexIn` xs) => HasIndexIn x xs
- type family Consumer xs r where ...
- type family (xs :: [k]) <> (ys :: [k]) :: [k] where ...
- type family Length (xs :: [k]) where ...
- type family Tail n xs where ...
- type family Init n xs where ...
- type family Replace x y xs where ...
- class Strengthen xs ys where
- strengthen :: Prod xs -> Prod ys
- remap :: forall x y xs. x `HasIndexIn` xs => (x -> y) -> Prod xs -> Prod (Replace x y xs)
The extensible product type
data Prod (xs :: [*]) Source #
An extensible product type
Construction and deconstruction
extract :: forall x xs. x `HasIndexIn` xs => Prod xs -> x Source #
Extract a value at a particular index
index :: forall x xs. x `HasIndexIn` xs => Word Source #
Computes the index of the given type in the given type level list.
tailN :: forall n xs. (KnownNat n, n <= Length xs) => Prod xs -> Prod (Tail n xs) Source #
Takes the tail of a product after the nth element.
initN :: forall n xs. (KnownNat n, n <= Length xs) => Prod xs -> Prod (Init n xs) Source #
Takes the initial length n segment of a product.
dropFirst :: forall x xs. Prod (x ': xs) -> Prod xs Source #
Drop the first element of a product. Sometimes needed for better type inference and less piping around of constraints.
class Consume xs where Source #
A typeclass that is useful to define the scott encoding/decoding for extensible products.
consume :: forall r. Prod xs -> Consumer xs r -> r Source #
produce :: (forall r. Consumer xs r -> r) -> Prod xs Source #
extend1 :: x -> Consumer xs (Prod (x ': xs)) Source #
cmap :: (r -> r') -> Consumer xs r -> Consumer xs r' Source #
Type families
type family IndexIn (x :: k) (xs :: [k]) where ... Source #
A type family for computing the index of a type in a list of types.
class KnownNat (x `IndexIn` xs) => HasIndexIn x xs Source #
A class that is used for convenience in order to make certain type signatures read more clearly.
Instances
KnownNat (IndexIn x xs) => HasIndexIn (x :: k) (xs :: [k]) Source # | |
Defined in Data.Prodder |
type family Consumer xs r where ... Source #
This is a reified pattern match on an extensible product
type family Length (xs :: [k]) where ... Source #
A type family for computing the length of a type level list
type family Init n xs where ... Source #
A type family for computing the initial segment of a type level list
type family Replace x y xs where ... Source #
Type family for replacing one type in a type level list with another
Rearranging and removing elements
class Strengthen xs ys where Source #
A typeclass to rearrange and possibly remove things from a product.
strengthen :: Prod xs -> Prod ys Source #
Instances
Strengthen xs ('[] :: [Type]) Source # | |
Defined in Data.Prodder strengthen :: Prod xs -> Prod '[] Source # | |
(Strengthen xs ys, HasIndexIn y xs) => Strengthen xs (y ': ys) Source # | |
Defined in Data.Prodder strengthen :: Prod xs -> Prod (y ': ys) Source # |