Safe Haskell | None |
---|---|
Language | Haskell98 |
Heterogeneous vectors.
- class Arity xs
- class Arity xs => ArityC c xs
- class Arity (Elems v) => HVector v where
- tupleSize :: forall v proxy. HVector v => proxy v -> Int
- class Arity (ElemsF v) => HVectorF v where
- tupleSizeF :: forall v f proxy. HVectorF v => proxy (v f) -> Int
- data Proxy k t :: forall k. k -> * = Proxy
- type ContVec xs = ContVecF xs Identity
- newtype ContVecF xs f = ContVecF {
- runContVecF :: forall r. TFun f xs r -> r
- asCVec :: ContVec xs -> ContVec xs
- asCVecF :: ContVecF f xs -> ContVecF f xs
- convert :: (HVector v, HVector w, Elems v ~ Elems w) => v -> w
- head :: (HVector v, Elems v ~ (a ': as), Arity as) => v -> a
- tail :: (HVector v, HVector w, (a ': Elems w) ~ Elems v) => v -> w
- cons :: (HVector v, HVector w, Elems w ~ (a ': Elems v)) => a -> v -> w
- concat :: (HVector v, HVector u, HVector w, Elems w ~ (Elems v ++ Elems u)) => v -> u -> w
- class ArityPeano n => Index n xs where
- index :: (Index n (Elems v), HVector v) => v -> proxy n -> ValueAt n (Elems v)
- set :: (Index n (Elems v), HVector v) => proxy n -> ValueAt n (Elems v) -> v -> v
- element :: forall n v a f proxy. (Index (Peano n) (Elems v), ValueAt (Peano n) (Elems v) ~ a, HVector v, Functor f) => proxy n -> (a -> f a) -> v -> f v
- elementCh :: forall n v w a b f proxy. (Index (Peano n) (Elems v), ValueAt (Peano n) (Elems v) ~ a, HVector v, HVector w, Elems w ~ NewElems (Peano n) (Elems v) b, Functor f) => proxy n -> (a -> f b) -> v -> f w
- mk0 :: forall v. (HVector v, Elems v ~ '[]) => v
- mk1 :: forall v a. (HVector v, Elems v ~ '[a]) => a -> v
- mk2 :: forall v a b. (HVector v, Elems v ~ '[a, b]) => a -> b -> v
- mk3 :: forall v a b c. (HVector v, Elems v ~ '[a, b, c]) => a -> b -> c -> v
- mk4 :: forall v a b c d. (HVector v, Elems v ~ '[a, b, c, d]) => a -> b -> c -> d -> v
- mk5 :: forall v a b c d e. (HVector v, Elems v ~ '[a, b, c, d, e]) => a -> b -> c -> d -> e -> v
- fold :: HVector v => v -> Fn Identity (Elems v) r -> r
- foldr :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> b -> b) -> b -> v -> b
- foldl :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => b -> a -> b) -> b -> v -> b
- foldrF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> b -> b) -> b -> v f -> b
- foldlF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => b -> f a -> b) -> b -> v f -> b
- foldrNatF :: HVectorF v => (forall a. f a -> b -> b) -> b -> v f -> b
- foldlNatF :: HVectorF v => (forall a. b -> f a -> b) -> b -> v f -> b
- mapM_ :: (HVector v, ArityC c (Elems v), Applicative f) => Proxy c -> (forall a. c a => a -> f ()) -> v -> f ()
- unfoldr :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => b -> (a, b)) -> b -> v
- unfoldrF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => b -> (f a, b)) -> b -> v f
- replicate :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall x. c x => x) -> v
- replicateM :: (HVector v, Applicative f, ArityC c (Elems v)) => Proxy c -> (forall a. c a => f a) -> f v
- replicateF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a) -> v f
- replicateNatF :: (HVectorF v, Arity (ElemsF v)) => (forall a. f a) -> v f
- zipWith :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> a -> a) -> v -> v -> v
- zipWithF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> g a -> h a) -> v f -> v g -> v h
- zipWithNatF :: HVectorF v => (forall a. f a -> g a -> h a) -> v f -> v g -> v h
- zipFold :: (HVector v, ArityC c (Elems v), Monoid m) => Proxy c -> (forall a. c a => a -> a -> m) -> v -> v -> m
- zipFoldF :: (HVectorF v, ArityC c (ElemsF v), Monoid m) => Proxy c -> (forall a. c a => f a -> f a -> m) -> v f -> v f -> m
- monomorphize :: (HVector v, Peano n ~ Len (Elems v), ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> x) -> v -> ContVec n x
- monomorphizeF :: (HVectorF v, Peano n ~ Len (ElemsF v), ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> x) -> v f -> ContVec n x
- mapNat :: HVectorF v => (forall a. f a -> g a) -> v f -> v g
- sequence :: (Applicative f, HVectorF v, HVector w, ElemsF v ~ Elems w) => v f -> f w
- sequence_ :: (Applicative f, HVectorF v) => v f -> f ()
- sequenceF :: (Applicative f, HVectorF v) => v (f `Compose` g) -> f (v g)
- wrap :: (HVector v, HVectorF w, Elems v ~ ElemsF w) => (forall a. a -> f a) -> v -> w f
- unwrap :: (HVectorF v, HVector w, ElemsF v ~ Elems w) => (forall a. f a -> a) -> v f -> w
- distribute :: (Functor f, HVector v, HVectorF w, Elems v ~ ElemsF w) => f v -> w f
- distributeF :: (Functor f, HVectorF v) => f (v g) -> v (f `Compose` g)
- eq :: (HVector v, ArityC Eq (Elems v)) => v -> v -> Bool
- compare :: (HVector v, ArityC Ord (Elems v)) => v -> v -> Ordering
- rnf :: (HVector v, ArityC NFData (Elems v)) => v -> ()
HVector type classes
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.
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.
construct :: Fun (Elems v) v Source #
Function for constructing vector
construct :: (Generic v, GHVector (Rep v), GElems (Rep v) ~ Elems v) => 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.
inspect :: (Generic v, GHVector (Rep v), GElems (Rep v) ~ Elems v) => 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 (VecList xs) Source # | |
Arity xs => HVector (HVec xs) Source # | |
HVector (a, b) Source # | |
(Unbox n a, HomArity (Peano n) a, KnownNat n, (~) PeanoNum (Peano ((+) n 1)) (S (Peano n))) => HVector (Vec n a) Source # | |
(Storable a, HomArity (Peano n) a, KnownNat n, (~) PeanoNum (Peano ((+) n 1)) (S (Peano n))) => HVector (Vec n a) Source # | |
(Prim a, HomArity (Peano n) a, KnownNat n, (~) PeanoNum (Peano ((+) n 1)) (S (Peano n))) => HVector (Vec n a) Source # | |
(HomArity (Peano n) a, KnownNat n, (~) PeanoNum (Peano ((+) n 1)) (S (Peano n))) => HVector (Vec n a) Source # | |
Arity xs => HVector (ContVecF xs Identity) Source # | |
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
tupleSizeF :: forall v f proxy. HVectorF v => proxy (v f) -> Int Source #
Number of elements in tuple
data Proxy k t :: forall k. k -> * #
A concrete, poly-kinded proxy type
Monad (Proxy *) | |
Functor (Proxy *) | |
Applicative (Proxy *) | |
Foldable (Proxy *) | |
Generic1 (Proxy *) | |
Eq1 (Proxy *) | Since: 4.9.0.0 |
Ord1 (Proxy *) | Since: 4.9.0.0 |
Read1 (Proxy *) | Since: 4.9.0.0 |
Show1 (Proxy *) | Since: 4.9.0.0 |
Alternative (Proxy *) | |
MonadPlus (Proxy *) | |
Vector (Proxy *) a | |
Bounded (Proxy k s) | |
Enum (Proxy k s) | |
Eq (Proxy k s) | |
Ord (Proxy k s) | |
Read (Proxy k s) | |
Show (Proxy k s) | |
Ix (Proxy k s) | |
Generic (Proxy k t) | |
Semigroup (Proxy k s) | |
Monoid (Proxy k s) | |
NFData (Proxy k a) | Since: 1.4.0.0 |
type Rep1 (Proxy *) | |
type Dim (Proxy *) | |
type Rep (Proxy k t) | |
newtype ContVecF xs f Source #
CPS-encoded partially heterogeneous vector.
ContVecF | |
|
asCVec :: ContVec xs -> ContVec xs Source #
Restrict type of vector to ContVec
. This function is useful for
resolving type ambiguity when composing functions. For example
following code would not compile because intermediate type is
ambiguous:
cons 'a' . tail
GHC cannot guess what type should be produced by tail
. However
we can fix type of intermediate vector with asCVec
, so code
below will work just fine:
cons 'a' . asCVec . tail
Position based functions
convert :: (HVector v, HVector w, Elems v ~ Elems w) => v -> w Source #
We can convert between any two vector which have same structure but different representations.
tail :: (HVector v, HVector w, (a ': Elems w) ~ Elems v) => v -> w Source #
Tail of the vector
>>>
case tail ('a',"aa",()) of x@(_,_) -> x
("aa",())
cons :: (HVector v, HVector w, Elems w ~ (a ': Elems v)) => a -> v -> w Source #
Prepend element to the list. Note that it changes type of vector so it either must be known from context of specified explicitly
concat :: (HVector v, HVector u, HVector w, Elems w ~ (Elems v ++ Elems u)) => v -> u -> w Source #
Concatenate two vectors
Indexing
class ArityPeano n => Index n xs Source #
Indexing of vectors
index :: (Index n (Elems v), HVector v) => v -> proxy n -> ValueAt n (Elems v) Source #
Index heterogeneous vector
set :: (Index n (Elems v), HVector v) => proxy n -> ValueAt n (Elems v) -> v -> v Source #
Set element in the vector
element :: forall n v a f proxy. (Index (Peano n) (Elems v), ValueAt (Peano n) (Elems v) ~ a, HVector v, Functor f) => proxy n -> (a -> f a) -> v -> f v Source #
Twan van Laarhoven's lens for i'th element.
elementCh :: forall n v w a b f proxy. (Index (Peano n) (Elems v), ValueAt (Peano n) (Elems v) ~ a, HVector v, HVector w, Elems w ~ NewElems (Peano n) (Elems v) b, Functor f) => proxy n -> (a -> f b) -> v -> f w Source #
Type changing Twan van Laarhoven's lens for i'th element.
Generic constructors
mk5 :: forall v a b c d e. (HVector v, Elems v ~ '[a, b, c, d, e]) => a -> b -> c -> d -> e -> v Source #
Folds and unfolds
fold :: HVector v => v -> Fn Identity (Elems v) r -> r Source #
Most generic form of fold which doesn't constrain elements id use
of inspect
. Or in more convenient form below:
>>>
fold (12::Int,"Str") (\a s -> show a ++ s)
"12Str"
foldr :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> b -> b) -> b -> v -> b Source #
Right fold over heterogeneous vector
foldl :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => b -> a -> b) -> b -> v -> b Source #
Left fold over heterogeneous vector
foldrF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> b -> b) -> b -> v f -> b Source #
Right fold over heterogeneous vector
foldlF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => b -> f a -> b) -> b -> v f -> b Source #
Left fold over heterogeneous vector
foldrNatF :: HVectorF v => (forall a. f a -> b -> b) -> b -> v f -> b Source #
Right fold over heterogeneous vector
foldlNatF :: HVectorF v => (forall a. b -> f a -> b) -> b -> v f -> b Source #
Left fold over heterogeneous vector
mapM_ :: (HVector v, ArityC c (Elems v), Applicative f) => Proxy c -> (forall a. c a => a -> f ()) -> v -> f () Source #
Apply monadic action to every element in the vector
unfoldr :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => b -> (a, b)) -> b -> v Source #
Unfold vector.
unfoldrF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => b -> (f a, b)) -> b -> v f Source #
Unfold vector.
Replicate variants
replicate :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall x. c x => x) -> v Source #
Replicate polymorphic value n times. Concrete instance for every element is determined by their respective types.
>>>
import Data.Vector.HFixed as H
>>>
H.replicate (Proxy :: Proxy Monoid) mempty :: ((),String)
((),"")
replicateM :: (HVector v, Applicative f, ArityC c (Elems v)) => Proxy c -> (forall a. c a => f a) -> f v Source #
Replicate monadic action n times.
>>>
import Data.Vector.HFixed as H
>>>
H.replicateM (Proxy :: Proxy Read) (fmap read getLine) :: IO (Int,Char)
> 12 > 'a' (12,'a')
replicateF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a) -> v f Source #
Zip variants
zipWith :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> a -> a) -> v -> v -> v Source #
Zip two heterogeneous vectors
zipWithF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> g a -> h a) -> v f -> v g -> v h Source #
Zip two heterogeneous vectors
zipWithNatF :: HVectorF v => (forall a. f a -> g a -> h a) -> v f -> v g -> v h Source #
Zip two heterogeneous vectors
zipFold :: (HVector v, ArityC c (Elems v), Monoid m) => Proxy c -> (forall a. c a => a -> a -> m) -> v -> v -> m Source #
zipFoldF :: (HVectorF v, ArityC c (ElemsF v), Monoid m) => Proxy c -> (forall a. c a => f a -> f a -> m) -> v f -> v f -> m Source #
monomorphize :: (HVector v, Peano n ~ Len (Elems v), ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> x) -> v -> ContVec n x Source #
Convert heterogeneous vector to homogeneous
monomorphizeF :: (HVectorF v, Peano n ~ Len (ElemsF v), ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> x) -> v f -> ContVec n x Source #
Convert heterogeneous vector to homogeneous
Tuples parametrized with type constructor
mapNat :: HVectorF v => (forall a. f a -> g a) -> v f -> v g Source #
Apply natural transformation to every element of the tuple.
sequence :: (Applicative f, HVectorF v, HVector w, ElemsF v ~ Elems w) => v f -> f w Source #
Sequence effects for every element in the vector
sequence_ :: (Applicative f, HVectorF v) => v f -> f () Source #
Sequence effects for every element in the vector
sequenceF :: (Applicative f, HVectorF v) => v (f `Compose` g) -> f (v g) Source #
Sequence effects for every element in the vector
wrap :: (HVector v, HVectorF w, Elems v ~ ElemsF w) => (forall a. a -> f a) -> v -> w f Source #
Wrap every value in the vector into type constructor.
unwrap :: (HVectorF v, HVector w, ElemsF v ~ Elems w) => (forall a. f a -> a) -> v f -> w Source #
Unwrap every value in the vector from the type constructor.
distribute :: (Functor f, HVector v, HVectorF w, Elems v ~ ElemsF w) => f v -> w f Source #
Analog of distribute from Distributive type class.
distributeF :: (Functor f, HVectorF v) => f (v g) -> v (f `Compose` g) Source #
Analog of distribute from Distributive type class.
Specialized operations
eq :: (HVector v, ArityC Eq (Elems v)) => v -> v -> Bool Source #
Generic equality for heterogeneous vectors