extensible-0.8: Extensible, efficient, optics-friendly data types and effects

Data.Extensible.Product

Description

Synopsis

# Basic operations

data (s :: [k]) :& (h :: k -> Type) Source #

The type of extensible products.

(:&) :: [k] -> (k -> Type) -> Type
Instances

nil :: '[] :& h Source #

An empty product.

(<:) :: h x -> (xs :& h) -> (x ': xs) :& h infixr 0 Source #

O(n) Prepend an element onto a product. Expressions like a <: b <: c <: nil are transformed to a single fromHList.

(<!) :: h x -> (xs :& h) -> (x ': xs) :& h infixr 0 Source #

Strict version of (<:).

(=<:) :: Wrapper h => Repr h x -> (xs :& h) -> (x ': xs) :& h infixr 0 Source #

hlength :: (xs :& h) -> Int Source #

The size of a product.

type family (xs :: [k]) ++ (ys :: [k]) :: [k] where ... infixr 5 Source #

Concatenate type level lists

Equations

 '[] ++ ys = ys (x ': xs) ++ ys = x ': (xs ++ ys)

happend :: (xs :& h) -> (ys :& h) -> (xs ++ ys) :& h infixr 5 Source #

Combine products.

hmap :: (forall x. g x -> h x) -> (xs :& g) -> xs :& h Source #

Transform every element in a product, preserving the order.

hmap idid
hmap (f . g) ≡ hmap f . hmap g

hmapWithIndex :: (forall x. Membership xs x -> g x -> h x) -> (xs :& g) -> xs :& h Source #

Map a function to every element of a product.

hzipWith :: (forall x. f x -> g x -> h x) -> (xs :& f) -> (xs :& g) -> xs :& h Source #

zipWith for heterogeneous product

hzipWith3 :: (forall x. f x -> g x -> h x -> i x) -> (xs :& f) -> (xs :& g) -> (xs :& h) -> xs :& i Source #

zipWith3 for heterogeneous product

hfoldMap :: Monoid a => (forall x. h x -> a) -> (xs :& h) -> a Source #

Map elements to a monoid and combine the results.

hfoldMap f . hmap g ≡ hfoldMap (f . g)

hfoldMapWithIndex :: Monoid a => (forall x. Membership xs x -> g x -> a) -> (xs :& g) -> a Source #

hfoldMap with the membership of elements.

hfoldrWithIndex :: (forall x. Membership xs x -> h x -> r -> r) -> r -> (xs :& h) -> r Source #

Right-associative fold of a product.

hfoldlWithIndex :: (forall x. Membership xs x -> r -> h x -> r) -> r -> (xs :& h) -> r Source #

Perform a strict left fold over the elements.

htraverse :: Applicative f => (forall x. g x -> f (h x)) -> (xs :& g) -> f (xs :& h) Source #

Traverse all elements and combine the result sequentially. htraverse (fmap f . g) ≡ fmap (hmap f) . htraverse g htraverse pure ≡ pure htraverse (Comp . fmap g . f) ≡ Comp . fmap (htraverse g) . htraverse f

htraverseWithIndex :: Applicative f => (forall x. Membership xs x -> g x -> f (h x)) -> (xs :& g) -> f (xs :& h) Source #

hsequence :: Applicative f => (xs :& Comp f h) -> f (xs :& h) Source #

sequence analog for extensible products

# Constrained fold

hmapWithIndexFor :: Forall c xs => proxy c -> (forall x. c x => Membership xs x -> g x -> h x) -> (xs :& g) -> xs :& h Source #

Map a function to every element of a product.

hfoldMapFor :: (Forall c xs, Monoid a) => proxy c -> (forall x. c x => h x -> a) -> (xs :& h) -> a Source #

Constrained hfoldMap

hfoldMapWithIndexFor :: (Forall c xs, Monoid a) => proxy c -> (forall x. c x => Membership xs x -> h x -> a) -> (xs :& h) -> a Source #

hfoldMapWithIndex with a constraint for each element.

hfoldrWithIndexFor :: forall c xs h r proxy. Forall c xs => proxy c -> (forall x. c x => Membership xs x -> h x -> r -> r) -> r -> (xs :& h) -> r Source #

hfoldrWithIndex with a constraint for each element.

hfoldlWithIndexFor :: Forall c xs => proxy c -> (forall x. c x => Membership xs x -> r -> h x -> r) -> r -> (xs :& h) -> r Source #

Constrained hfoldlWithIndex

# Constraind fold without proxies

hfoldMapWith :: forall c xs h a. (Forall c xs, Monoid a) => (forall x. c x => h x -> a) -> (xs :& h) -> a Source #

Constrained hfoldMap

hfoldMapWithIndexWith :: forall c xs h a. (Forall c xs, Monoid a) => (forall x. c x => Membership xs x -> h x -> a) -> (xs :& h) -> a Source #

hfoldMapWithIndex with a constraint for each element.

hfoldrWithIndexWith :: forall c xs h r. Forall c xs => (forall x. c x => Membership xs x -> h x -> r -> r) -> r -> (xs :& h) -> r Source #

hfoldlWithIndexWith :: forall c xs h r. Forall c xs => (forall x. c x => Membership xs x -> r -> h x -> r) -> r -> (xs :& h) -> r Source #

Constrained hfoldlWithIndex

hmapWithIndexWith :: forall c xs g h. Forall c xs => (forall x. c x => Membership xs x -> g x -> h x) -> (xs :& g) -> xs :& h Source #

# Evaluating

hforce :: (xs :& h) -> xs :& h Source #

Evaluate every element in a product.

# Update

haccumMap :: Foldable f => (a -> xs :/ g) -> (forall x. Membership xs x -> g x -> h x -> h x) -> (xs :& h) -> f a -> xs :& h Source #

Accumulate sums on a product.

haccum :: Foldable f => (forall x. Membership xs x -> g x -> h x -> h x) -> (xs :& h) -> f (xs :/ g) -> xs :& h Source #

haccum = haccumMap id

hpartition :: (Foldable f, Generate xs) => (a -> xs :/ h) -> f a -> xs :& Comp [] h Source #

Group sums by type.

# Lookup

hlookup :: Membership xs x -> (xs :& h) -> h x Source #

Get an element in a product.

hindex :: (xs :& h) -> Membership xs x -> h x Source #

Flipped hlookup

# Generation

class Generate (xs :: [k]) where #

Every type-level list is an instance of Generate.

Methods

henumerate :: (forall (x :: k). Membership xs x -> r -> r) -> r -> r #

Enumerate all possible Memberships of xs.

hcount :: proxy xs -> Int #

Count the number of memberships.

hgenerateList :: Applicative f => (forall (x :: k). Membership xs x -> f (h x)) -> f (HList h xs) #

Enumerate Memberships and construct an HList.

Instances
 Generate ([] :: [k]) Instance detailsDefined in Type.Membership Methodshenumerate :: (forall (x :: k0). Membership [] x -> r -> r) -> r -> r #hcount :: proxy [] -> Int #hgenerateList :: Applicative f => (forall (x :: k0). Membership [] x -> f (h x)) -> f (HList h []) # Generate xs => Generate (x ': xs :: [k]) Instance detailsDefined in Type.Membership Methodshenumerate :: (forall (x0 :: k0). Membership (x ': xs) x0 -> r -> r) -> r -> r #hcount :: proxy (x ': xs) -> Int #hgenerateList :: Applicative f => (forall (x0 :: k0). Membership (x ': xs) x0 -> f (h x0)) -> f (HList h (x ': xs)) #

hgenerate :: (Generate xs, Applicative f) => (forall x. Membership xs x -> f (h x)) -> f (xs :& h) Source #

htabulate :: Generate xs => (forall x. Membership xs x -> h x) -> xs :& h Source #

Construct a product using a function which takes a Membership.

hmap f (htabulate g) ≡ htabulate (f . g)
htabulate (hindex m) ≡ m
hindex (htabulate k) ≡ k

hrepeat :: Generate xs => (forall x. h x) -> xs :& h Source #

A product filled with the specified value.

hcollect :: (Functor f, Generate xs) => (a -> xs :& h) -> f a -> xs :& Comp f h Source #

The dual of htraverse

hdistribute :: (Functor f, Generate xs) => f (xs :& h) -> xs :& Comp f h Source #

The dual of hsequence

fromHList :: HList h xs -> xs :& h Source #

Convert HList into a product.

toHList :: forall h xs. (xs :& h) -> HList h xs Source #

Convert a product into an HList.

class (ForallF c xs, Generate xs) => Forall (c :: k -> Constraint) (xs :: [k]) where #

Every element in xs satisfies c

Methods

henumerateFor :: proxy c -> proxy' xs -> (forall (x :: k). c x => Membership xs x -> r -> r) -> r -> r #

Enumerate all possible Memberships of xs with an additional context.

hgenerateListFor :: Applicative f => proxy c -> (forall (x :: k). c x => Membership xs x -> f (h x)) -> f (HList h xs) #

Instances
 Forall (c :: k -> Constraint) ([] :: [k]) Instance detailsDefined in Type.Membership MethodshenumerateFor :: proxy c -> proxy' [] -> (forall (x :: k0). c x => Membership [] x -> r -> r) -> r -> r #hgenerateListFor :: Applicative f => proxy c -> (forall (x :: k0). c x => Membership [] x -> f (h x)) -> f (HList h []) # (c x, Forall c xs) => Forall (c :: a -> Constraint) (x ': xs :: [a]) Instance detailsDefined in Type.Membership MethodshenumerateFor :: proxy c -> proxy' (x ': xs) -> (forall (x0 :: k). c x0 => Membership (x ': xs) x0 -> r -> r) -> r -> r #hgenerateListFor :: Applicative f => proxy c -> (forall (x0 :: k). c x0 => Membership (x ': xs) x0 -> f (h x0)) -> f (HList h (x ': xs)) #

hgenerateFor :: (Forall c xs, Applicative f) => proxy c -> (forall x. c x => Membership xs x -> f (h x)) -> f (xs :& h) Source #

htabulateFor :: Forall c xs => proxy c -> (forall x. c x => Membership xs x -> h x) -> xs :& h Source #

Pure version of hgenerateFor.

hrepeatFor :: Forall c xs => proxy c -> (forall x. c x => h x) -> xs :& h Source #

A product filled with the specified value.

hgenerateWith :: forall c xs f h. (Forall c xs, Applicative f) => (forall x. c x => Membership xs x -> f (h x)) -> f (xs :& h) Source #

htabulateWith :: forall c xs h. Forall c xs => (forall x. c x => Membership xs x -> h x) -> xs :& h Source #

Pure version of hgenerateFor.

hrepeatWith :: forall c xs h. Forall c xs => (forall x. c x => h x) -> xs :& h Source #

A product filled with the specified value.