fixed-vector-hetero-0.2.0.0: Generic heterogeneous vectors

Safe HaskellNone

Data.Vector.HFixed.Cont

Contents

Description

CPS encoded heterogeneous vectors.

Synopsis

CPS-encoded vector

Type classes

type family Fn as b Source

Type family for N-ary function. Types of function parameters are encoded as the list of types.

newtype Fun as b Source

Newtype wrapper to work around of type families' lack of injectivity.

Constructors

Fun 

Fields

unFun :: Fn as b
 

Instances

Arity xs => Monad (Fun xs) 
Arity xs => Functor (Fun xs) 
Arity xs => Applicative (Fun xs) 

newtype TFun f as b Source

Newtype wrapper for function where all type parameters have same type constructor. This type is required for writing function which works with monads, appicatives etc.

Constructors

TFun 

Fields

unTFun :: Fn (Wrap f as) b
 

Instances

Arity xs => Monad (TFun * f xs) 
Arity xs => Functor (TFun * f xs) 
Arity xs => Applicative (TFun * f xs) 

class Arity (Len xs) => Arity xs whereSource

Type class for dealing with N-ary function in generic way. Both accum and apply work with accumulator data types which are polymorphic. So it's only possible to write functions which rearrange elements in vector using plain ADT. It's possible to get around it by using GADT as accumulator (See ArityC and function which use it)

This is also somewhat a kitchen sink module. It contains witnesses which could be used to prove type equalities or to bring instance in scope.

Methods

accumSource

Arguments

:: (forall a as. t (a : as) -> a -> t as)

Step function. Applies element to accumulator.

-> (t `[]` -> b)

Extract value from accumulator.

-> t xs

Initial state.

-> Fn xs b 

Fold over N elements exposed as N-ary function.

applySource

Arguments

:: (forall a as. t (a : as) -> (a, t as))

Extract value to be applied to function.

-> t xs

Initial state.

-> ContVec xs 

Apply values to N-ary function

applyMSource

Arguments

:: Monad m 
=> (forall a as. t (a : as) -> m (a, t as))

Extract value to be applied to function

-> t xs

Initial state

-> m (ContVec xs) 

Apply value to N-ary function using monadic actions

accumTy :: (forall a as. t (a : as) -> f a -> t as) -> (t `[]` -> b) -> t xs -> Fn (Wrap f xs) bSource

Analog of accum

applyTy :: (forall a as. t (a : as) -> (f a, t as)) -> t xs -> ContVecF xs fSource

Analog of apply which allows to works with vectors which elements are wrapped in the newtype constructor.

arity :: p xs -> IntSource

Size of type list as integer.

witWrapped :: WitWrapped f xsSource

witConcat :: Arity ys => WitConcat xs ysSource

witNestedFun :: WitNestedFun xs ys rSource

witLenWrap :: WitLenWrap f xsSource

Instances

Arity ([] *) 
Arity xs => Arity (: * x xs) 

class Arity (Elems v) => HVector v whereSource

Type class for heterogeneous vectors. Instance should specify way to construct and deconstruct itself

Note that this type class is extremely generic. Almost any single constructor data type could be made instance. It could be monomorphic, it could be polymorphic in some or all fields it doesn't matter. Only law instance should obey is:

 inspect v construct = v

Default implementation which uses Generic is provided.

Associated Types

type Elems v :: [*]Source

Methods

construct :: Fun (Elems v) vSource

Function for constructing vector

inspect :: v -> Fun (Elems v) a -> aSource

Function for deconstruction of vector. It applies vector's elements to N-ary function.

Instances

HVector ()

Unit is empty heterogeneous vector

HVector (Complex a) 
Arity xs => HVector (ContVec xs) 
Arity xs => HVector (VecList xs) 
Arity xs => HVector (HVec xs) 
HVector (a, b) 
(Storable a, HomArity n a) => HVector (Vec n a) 
(Unbox n a, HomArity n a) => HVector (Vec n a) 
(Prim a, HomArity n a) => HVector (Vec n a) 
HomArity n a => HVector (Vec n a) 
(Arity (Wrap * * f xs), Arity xs) => HVector (HVecF xs f)

It's not possible to remove constrain Arity (Wrap f xs) because it's required by superclass and we cannot prove it for all f. witWrapped allow to generate proofs for terms

HVector (a, b, c) 
HVector (a, b, c, d) 
HVector (a, b, c, d, e) 
HVector (a, b, c, d, e, f) 
HVector (a, b, c, d, e, f, g) 

class Arity (ElemsF v) => HVectorF v whereSource

Type class for partially homogeneous vector where every element in the vector have same type constructor. Vector itself is parametrized by that constructor

Associated Types

type ElemsF v :: [*]Source

Elements of the vector without type constructors

Methods

inspectF :: v f -> TFun f (ElemsF v) a -> aSource

constructF :: TFun f (ElemsF v) (v f)Source

Instances

Arity xs => HVectorF (VecListF xs) 
Arity xs => HVectorF (HVecF xs) 
Arity xs => HVectorF (ContVecF * xs) 

class Arity n => Index n xs Source

Indexing of vectors

Associated Types

type ValueAt n xs :: *Source

Type at position n

Instances

Arity xs => Index Z (: * x xs) 
Index n xs => Index (S n) (: * x xs) 

type family Wrap f a :: [β]Source

Wrap every element of list into type constructor

CPS-encoded vector

newtype ContVec xs Source

CPS-encoded heterogeneous vector.

Constructors

ContVec 

Fields

runContVec :: forall r. Fun xs r -> r
 

Instances

Arity xs => HVector (ContVec xs) 

newtype ContVecF xs f Source

CPS-encoded partially heterogeneous vector.

Constructors

ContVecF (forall r. TFun f xs r -> r) 

Instances

Arity xs => HVectorF (ContVecF * xs) 

Other data types

data VecList whereSource

List like heterogeneous vector.

Constructors

Nil :: VecList `[]` 
Cons :: x -> VecList xs -> VecList (x : xs) 

Instances

Arity xs => HVector (VecList xs) 

data VecListF xs f whereSource

List-like vector

Constructors

NilF :: VecListF `[]` f 
ConsF :: f x -> VecListF xs f -> VecListF (x : xs) f 

Instances

Arity xs => HVectorF (VecListF xs) 

Conversion to/from vector

cvec :: (HVector v, Elems v ~ xs) => v -> ContVec xsSource

Convert heterogeneous vector to CPS form

vector :: (HVector v, Elems v ~ xs) => ContVec xs -> vSource

Convert CPS-vector to heterogeneous vector

cvecF :: HVectorF v => v f -> ContVecF (ElemsF v) fSource

vectorF :: HVectorF v => ContVecF (ElemsF v) f -> v fSource

Position based functions

head :: forall x xs. Arity xs => ContVec (x : xs) -> xSource

Head of vector

tail :: ContVec (x : xs) -> ContVec xsSource

Tail of CPS-encoded vector

cons :: x -> ContVec xs -> ContVec (x : xs)Source

Cons element to the vector

consF :: f x -> ContVecF xs f -> ContVecF (x : xs) fSource

Cons element to the vector

concat :: Arity xs => ContVec xs -> ContVec ys -> ContVec (xs ++ ys)Source

Concatenate two vectors

Indexing

index :: Index n xs => ContVec xs -> n -> ValueAt n xsSource

Get value at nth position.

set :: Index n xs => n -> ValueAt n xs -> ContVec xs -> ContVec xsSource

Set value on nth position.

Constructors

mk1 :: a -> ContVec `[a]`Source

mk2 :: a -> b -> ContVec `[a, b]`Source

mk3 :: a -> b -> c -> ContVec `[a, b, c]`Source

mk4 :: a -> b -> c -> d -> ContVec `[a, b, c, d]`Source

mk5 :: a -> b -> c -> d -> e -> ContVec `[a, b, c, d, e]`Source

Folds and unfolds

foldl :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => b -> a -> b) -> b -> ContVec xs -> bSource

Left fold over vector

foldr :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => a -> b -> b) -> b -> ContVec xs -> bSource

Right fold over vector

unfoldr :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => b -> (a, b)) -> b -> ContVec xsSource

Unfold vector.

Polymorphic values

replicate :: forall xs c. ArityC c xs => Proxy c -> (forall x. c x => x) -> ContVec xsSource

Replicate polymorphic value n times. Concrete instance for every element is determined by their respective types.

replicateM :: forall xs c m. (ArityC c xs, Monad m) => Proxy c -> (forall x. c x => m x) -> m (ContVec xs)Source

Replicate monadic action n times.

zipMono :: forall xs c. ArityC c xs => Proxy c -> (forall a. c a => a -> a -> a) -> ContVec xs -> ContVec xs -> ContVec xsSource

Zip two heterogeneous vectors

zipMonoF :: forall xs f c. ArityC c xs => Proxy c -> (forall a. c a => f a -> f a -> f a) -> ContVecF xs f -> ContVecF xs f -> ContVecF xs fSource

Zip two heterogeneous vectors

zipFold :: forall xs c m. (ArityC c xs, Monoid m) => Proxy c -> (forall a. c a => a -> a -> m) -> ContVec xs -> ContVec xs -> mSource

Zip vector and fold result using monoid

monomorphize :: forall c xs a. ArityC c xs => Proxy c -> (forall x. c x => x -> a) -> ContVec xs -> ContVec (Len xs) aSource

Convert heterogeneous vector to homogeneous

monomorphizeF :: forall c xs a f. ArityC c xs => Proxy c -> (forall x. c x => f x -> a) -> ContVecF xs f -> ContVec (Len xs) aSource

Convert heterogeneous vector to homogeneous

Vector parametrized with type constructor

mapFunctor :: Arity xs => (forall a. f a -> g a) -> ContVecF xs f -> ContVecF xs gSource

Map functor.

sequence :: (Arity xs, Monad m) => ContVecF xs m -> m (ContVec xs)Source

Sequence vector's elements

sequenceA :: (Arity xs, Applicative f) => ContVecF xs f -> f (ContVec xs)Source

Sequence vector's elements

sequenceF :: (Arity xs, Monad m) => ContVecF xs (m `Compose` f) -> m (ContVecF xs f)Source

Sequence vector's elements

sequenceAF :: (Arity xs, Applicative f) => ContVecF xs (f `Compose` g) -> f (ContVecF xs g)Source

Sequence vector's elements

distribute :: forall f xs. (Arity xs, Functor f) => f (ContVec xs) -> ContVecF xs fSource

distributeF :: forall f g xs. (Arity xs, Functor f) => f (ContVecF xs g) -> ContVecF xs (f `Compose` g)Source

wrap :: Arity xs => (forall a. a -> f a) -> ContVec xs -> ContVecF xs fSource

Wrap every value in the vector into type constructor.

unwrap :: Arity xs => (forall a. f a -> a) -> ContVecF xs f -> ContVec xsSource

Unwrap every value in the vector from the type constructor.