extensible-0.2.4: Poly-kinded, extensible ADTs

Copyright(c) Fumiaki Kinoshita 2015
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Product

Contents

Description

 

Synopsis

Product

data h :* s where Source

The extensible product type

Constructors

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

Instances

Typeable ((k -> *) -> [k] -> *) ((:*) k) 
Forall k (ClassComp * k Eq h) xs => Eq ((:*) k h xs) 
(Forall k (ClassComp * k Eq h) xs, Forall k (ClassComp * k Ord h) xs) => Ord ((:*) k h xs) 
(Show ((:*) k h xs), Show (h x)) => Show ((:*) k h ((:) k x xs)) 
Show ((:*) k h ([] k)) 

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

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

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

Serial combination of two products.

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

O(1) Extract the head element.

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

O(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.

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

Combine all elements.

htraverse :: Applicative f => (forall x. h x -> f (h x)) -> (h :* xs) -> f (h :* xs) Source

Traverse all elements.

htabulate :: forall g h xs. (forall x. Position xs x -> g x -> h x) -> (g :* xs) -> h :* xs Source

hmap with its indices.

hlookup :: Position xs x -> (h :* xs) -> h x Source

O(log n) Pick up an elemtnt.

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

O(log n) A lens for a specific element.

sectorAt :: forall h x xs f. Functor f => Position xs x -> (h x -> f (h x)) -> (h :* xs) -> f (h :* xs) Source

O(log n) A lens for a value in a known position.

class Generate xs where Source

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

Methods

generate :: (forall x. Position xs x -> h x) -> h :* xs Source

Instances

Generate k ([] k) 
(Generate k (Half k xs), Generate k (Half k (Tail k xs))) => Generate k ((:) k x xs) 

class Forall c xs where Source

Guarantees the all elements satisfies the predicate.

Methods

generateFor :: proxy c -> (forall x. c x => Position xs x -> h x) -> h :* xs Source

Instances

Forall k c ([] k) 
(c x, Forall k c (Half k xs), Forall k c (Half k (Tail k xs))) => Forall k c ((:) k x xs)