extensible-0.3.7: Extensible, efficient, optics-friendly data types

Copyright(c) Fumiaki Kinoshita 2015
LicenseBSD3
MaintainerFumiaki Kinoshita <[email protected]>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Extensible.Product

Contents

Description

 

Synopsis

Basic operations

data h :* s where Source #

The type of extensible products.

(:*) :: (k -> *) -> [k] -> *

Constructors

Nil :: h :* '[] 
Tree :: !(h x) -> (h :* Half xs) -> (h :* Half (Tail xs)) -> h :* (x ': xs) 

Instances

Functor f => Extensible k f (->) ((:*) k) Source # 

Methods

pieceAt :: Membership f xs x -> Optic' * * ((:*) k) (->) (t h xs) (h x) Source #

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

O(log n) Add an element to a product.

(<:*) :: forall h x xs. h x -> (h :* xs) -> h :* (x ': xs) infixr 0 Source #

An alias for (<:).

(*++*) :: (h :* xs) -> (h :* ys) -> h :* (xs ++ ys) infixr 0 Source #

Combine products.

hhead :: (h :* (x ': xs)) -> h x Source #

O(1) Extract the head element.

htail :: (h :* (x ': xs)) -> h :* xs Source #

O(log n) Extract the tail of the product.

huncons :: forall h x xs. (h :* (x ': xs)) -> (h x, h :* xs) Source #

Split a product to the head and the tail.

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

Transform every elements in a product, preserving the order.

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

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

htrans :: (forall x. g x -> h (t x)) -> (g :* xs) -> h :* Map t xs Source #

Transform every elements in a product, preserving the order.

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

zipWith for heterogeneous product

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

zipWith3 for heterogeneous product

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

Map elements to a monoid and combine the results.

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

htraverse :: Applicative f => (forall x. g x -> f (h x)) -> (g :* xs) -> f (h :* xs) 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 :: forall f g h xs. Applicative f => (forall x. Membership xs x -> g x -> f (h x)) -> (g :* xs) -> f (h :* xs) Source #

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

sequence analog for extensible products

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

The dual of htraverse

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

The dual of hsequence

Lookup

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

O(log n) Pick up an elemtnt.

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

Flipped hlookup

sectorAt :: Functor f => Membership xs x -> (h x -> f (h x)) -> (h :* xs) -> f (h :* xs) Source #

Deprecated: Use pieceAt

The legacy name for pieceAt

sector :: (Functor f, x xs) => (h x -> f (h x)) -> (h :* xs) -> f (h :* xs) Source #

Deprecated: Use piece

The legacy name for piece

Generation

class Generate xs where Source #

Given a function that maps types to values, we can "collect" entities all you want.

Minimal complete definition

hgenerate

Methods

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

O(n) Generate a product with the given function.

Instances

Generate k ([] k) Source # 

Methods

hgenerate :: Applicative f => (forall x. Membership [k] xs x -> f (h x)) -> f (([k] :* h) xs) Source #

(Generate k (Half k xs), Generate k (Half k (Tail k xs))) => Generate k ((:) k x xs) Source # 

Methods

hgenerate :: Applicative f => (forall a. Membership ((k ': x) xs) xs a -> f (h a)) -> f (((k ': x) xs :* h) xs) Source #

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

Pure version of hgenerate.

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

class Forall c xs where Source #

Guarantees the all elements satisfies the predicate.

Minimal complete definition

hgenerateFor

Methods

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

O(n) Analogous to hgenerate, but it also supplies a context c x for every elements in xs.

Instances

Forall k c ([] k) Source # 

Methods

hgenerateFor :: Applicative f => proxy [k] -> (forall x. [k] x => Membership c xs x -> f (h x)) -> f ((c :* h) xs) Source #

(c x, Forall a c (Half a xs), Forall a c (Half a (Tail a xs))) => Forall a c ((:) a x xs) Source # 

Methods

hgenerateFor :: Applicative f => proxy ((a ': x) xs) -> (forall b. (a ': x) xs b => Membership c xs b -> f (h b)) -> f ((c :* h) xs) Source #

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

Pure version of hgenerateFor.