Safe Haskell | None |
---|---|
Language | Haskell98 |
CPS encoded heterogeneous vectors.
- type family Fn as b
- newtype Fun as b = Fun {}
- newtype TFun f as b = TFun {}
- class Arity (Len xs) => Arity xs where
- accum :: (forall a as. t (a : as) -> a -> t as) -> (t `[]` -> b) -> t xs -> Fn xs b
- apply :: (forall a as. t (a : as) -> (a, t as)) -> t xs -> ContVec xs
- applyM :: Monad m => (forall a as. t (a : as) -> m (a, t as)) -> t xs -> m (ContVec xs)
- accumTy :: (forall a as. t (a : as) -> f a -> t as) -> (t `[]` -> b) -> t xs -> Fn (Wrap f xs) b
- applyTy :: (forall a as. t (a : as) -> (f a, t as)) -> t xs -> ContVecF xs f
- arity :: p xs -> Int
- witWrapped :: WitWrapped f xs
- witConcat :: Arity ys => WitConcat xs ys
- witNestedFun :: WitNestedFun xs ys r
- witLenWrap :: WitLenWrap f xs
- class Arity (Elems v) => HVector v where
- class Arity (ElemsF v) => HVectorF v where
- class Arity n => Index n xs where
- type ValueAt n xs :: *
- type family Wrap f a :: [β]
- newtype ContVec xs = ContVec {
- runContVec :: forall r. Fun xs r -> r
- newtype ContVecF xs f = ContVecF (forall r. TFun f xs r -> r)
- toContVec :: ContVecF xs f -> ContVec (Wrap f xs)
- toContVecF :: ContVec (Wrap f xs) -> ContVecF xs f
- data VecList :: [*] -> * where
- data VecListF xs f where
- cvec :: (HVector v, Elems v ~ xs) => v -> ContVec xs
- vector :: (HVector v, Elems v ~ xs) => ContVec xs -> v
- cvecF :: HVectorF v => v f -> ContVecF (ElemsF v) f
- vectorF :: HVectorF v => ContVecF (ElemsF v) f -> v f
- head :: forall x xs. Arity xs => ContVec (x : xs) -> x
- tail :: ContVec (x : xs) -> ContVec xs
- cons :: x -> ContVec xs -> ContVec (x : xs)
- consF :: f x -> ContVecF xs f -> ContVecF (x : xs) f
- concat :: Arity xs => ContVec xs -> ContVec ys -> ContVec (xs ++ ys)
- index :: Index n xs => ContVec xs -> n -> ValueAt n xs
- set :: Index n xs => n -> ValueAt n xs -> ContVec xs -> ContVec xs
- mk0 :: ContVec `[]`
- mk1 :: a -> ContVec `[a]`
- mk2 :: a -> b -> ContVec `[a, b]`
- mk3 :: a -> b -> c -> ContVec `[a, b, c]`
- mk4 :: a -> b -> c -> d -> ContVec `[a, b, c, d]`
- mk5 :: a -> b -> c -> d -> e -> ContVec `[a, b, c, d, e]`
- foldl :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => b -> a -> b) -> b -> ContVec xs -> b
- foldr :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => a -> b -> b) -> b -> ContVec xs -> b
- unfoldr :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => b -> (a, b)) -> b -> ContVec xs
- replicate :: forall xs c. ArityC c xs => Proxy c -> (forall x. c x => x) -> ContVec xs
- replicateM :: forall xs c m. (ArityC c xs, Monad m) => Proxy c -> (forall x. c x => m x) -> m (ContVec xs)
- replicateF :: forall f xs. Arity xs => (forall a. f a) -> ContVecF xs f
- zipMono :: forall xs c. ArityC c xs => Proxy c -> (forall a. c a => a -> a -> a) -> ContVec xs -> ContVec xs -> ContVec xs
- zipMonoF :: forall xs f g h c. ArityC c xs => Proxy c -> (forall a. c a => f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g -> ContVecF xs h
- zipFold :: forall xs c m. (ArityC c xs, Monoid m) => Proxy c -> (forall a. c a => a -> a -> m) -> ContVec xs -> ContVec xs -> m
- monomorphize :: forall c xs a. ArityC c xs => Proxy c -> (forall x. c x => x -> a) -> ContVec xs -> ContVec (Len xs) a
- monomorphizeF :: forall c xs a f. ArityC c xs => Proxy c -> (forall x. c x => f x -> a) -> ContVecF xs f -> ContVec (Len xs) a
- mapFunctor :: Arity xs => (forall a. f a -> g a) -> ContVecF xs f -> ContVecF xs g
- sequence :: (Arity xs, Monad m) => ContVecF xs m -> m (ContVec xs)
- sequenceA :: (Arity xs, Applicative f) => ContVecF xs f -> f (ContVec xs)
- sequenceF :: (Arity xs, Monad m) => ContVecF xs (m `Compose` f) -> m (ContVecF xs f)
- sequenceAF :: (Arity xs, Applicative f) => ContVecF xs (f `Compose` g) -> f (ContVecF xs g)
- distribute :: forall f xs. (Arity xs, Functor f) => f (ContVec xs) -> ContVecF xs f
- distributeF :: forall f g xs. (Arity xs, Functor f) => f (ContVecF xs g) -> ContVecF xs (f `Compose` g)
- wrap :: Arity xs => (forall a. a -> f a) -> ContVec xs -> ContVecF xs f
- unwrap :: Arity xs => (forall a. f a -> a) -> ContVecF xs f -> ContVec xs
CPS-encoded vector
Type classes
Type family for N-ary function. Types of function parameters are encoded as the list of types.
Newtype wrapper to work around of type families' lack of injectivity.
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.
class Arity (Len xs) => Arity xs where Source
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.
:: (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.
:: (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
:: 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) b Source
Analog of accum
applyTy :: (forall a as. t (a : as) -> (f a, t as)) -> t xs -> ContVecF xs f Source
Analog of apply
which allows to works with vectors which
elements are wrapped in the newtype constructor.
Size of type list as integer.
witWrapped :: WitWrapped f xs Source
witConcat :: Arity ys => WitConcat xs ys Source
witNestedFun :: WitNestedFun xs ys r Source
witLenWrap :: WitLenWrap f xs Source
class Arity (Elems v) => HVector v where Source
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.
Nothing
construct :: Fun (Elems v) v Source
Function for constructing vector
inspect :: v -> Fun (Elems v) a -> a Source
Function for deconstruction of vector. It applies vector's elements to N-ary function.
HVector () Source | Unit is empty heterogeneous vector |
HVector (Complex a) Source | |
Arity xs => HVector (ContVec xs) Source | |
Arity xs => HVector (VecList xs) Source | |
Arity xs => HVector (HVec xs) Source | |
HVector (a, b) Source | |
(Storable a, HomArity n a) => HVector (Vec n a) Source | |
(Unbox n a, HomArity n a) => HVector (Vec n a) Source | |
(Prim a, HomArity n a) => HVector (Vec n a) Source | |
HomArity n a => HVector (Vec n a) Source | |
(Arity (Wrap * * f xs), Arity xs) => HVector (HVecF xs f) Source | It's not possible to remove constrain |
HVector (a, b, c) Source | |
HVector (a, b, c, d) Source | |
HVector (a, b, c, d, e) Source | |
HVector (a, b, c, d, e, f) Source | |
HVector (a, b, c, d, e, f, g) Source | |
HVector (a, b, c, d, e, f, g, h) Source | |
HVector (a, b, c, d, e, f, g, h, i) Source | |
HVector (a, b, c, d, e, f, g, h, i, j) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a') Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a', b') Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a', b', c') Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a', b', c', d') Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a', b', c', d', e') Source | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a', b', c', d', e', f') Source |
class Arity (ElemsF v) => HVectorF v where Source
Type class for partially homogeneous vector where every element in the vector have same type constructor. Vector itself is parametrized by that constructor
CPS-encoded vector
CPS-encoded heterogeneous vector.
ContVec | |
|
CPS-encoded partially heterogeneous vector.
toContVecF :: ContVec (Wrap f xs) -> ContVecF xs f Source
Other data types
Conversion to/from vector
vector :: (HVector v, Elems v ~ xs) => ContVec xs -> v Source
Convert CPS-vector to heterogeneous vector
Position based functions
Indexing
Constructors
Folds and unfolds
foldl :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => b -> a -> b) -> b -> ContVec xs -> b Source
Left fold over vector
foldr :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => a -> b -> b) -> b -> ContVec xs -> b Source
Right fold over vector
unfoldr :: forall xs c b. ArityC c xs => Proxy c -> (forall a. c a => b -> (a, b)) -> b -> ContVec xs Source
Unfold vector.
Polymorphic values
replicate :: forall xs c. ArityC c xs => Proxy c -> (forall x. c x => x) -> ContVec xs Source
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.
replicateF :: forall f xs. Arity xs => (forall a. f a) -> ContVecF xs f Source
zipMono :: forall xs c. ArityC c xs => Proxy c -> (forall a. c a => a -> a -> a) -> ContVec xs -> ContVec xs -> ContVec xs Source
Zip two heterogeneous vectors
zipMonoF :: forall xs f g h c. ArityC c xs => Proxy c -> (forall a. c a => f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g -> ContVecF xs h Source
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 -> m Source
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) a Source
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) a Source
Convert heterogeneous vector to homogeneous
Vector parametrized with type constructor
mapFunctor :: Arity xs => (forall a. f a -> g a) -> ContVecF xs f -> ContVecF xs g Source
Map functor.
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
distributeF :: forall f g xs. (Arity xs, Functor f) => f (ContVecF xs g) -> ContVecF xs (f `Compose` g) Source