Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.Vector.HFixed.Class
Contents
- data S n :: * -> *
- data Z :: *
- class ((~) Nat (ToNat a) b, (~) * (ToPeano b) a) => NatIso a b
- type family ToPeano (b :: Nat) :: * where ...
- type family ToNat a :: Nat where ...
- type family Fn (as :: [*]) b
- newtype Fun as b = Fun {}
- newtype TFun f as b = TFun {}
- funToTFun :: Fun (Wrap f xs) b -> TFun f xs b
- tfunToFun :: TFun f xs b -> Fun (Wrap f xs) b
- data Proxy k t :: forall k. k -> * = Proxy
- type family (xs :: [α]) ++ (ys :: [α]) :: [α]
- type family Len (xs :: [α]) :: *
- type family Wrap (f :: α -> β) (a :: [α]) :: [β]
- type family HomList n (a :: α) :: [α]
- class Arity (Len xs) => Arity xs where
- class Arity xs => ArityC c xs where
- class Arity (Elems v) => HVector v where
- class Arity (ElemsF v) => HVectorF v where
- data WitWrapped f xs where
- WitWrapped :: Arity (Wrap f xs) => WitWrapped f xs
- data WitConcat xs ys where
- data WitNestedFun xs ys r where
- WitNestedFun :: Fn (xs ++ ys) r ~ Fn xs (Fn ys r) => WitNestedFun xs ys r
- data WitLenWrap f xs where
- WitLenWrap :: Len xs ~ Len (Wrap f xs) => WitLenWrap f xs
- data WitWrapIndex f n xs where
- WitWrapIndex :: (ValueAt n (Wrap f xs) ~ f (ValueAt n xs), Index n (Wrap f xs), Arity (Wrap f xs)) => WitWrapIndex f n xs
- data WitAllInstances c xs where
- WitAllInstancesNil :: WitAllInstances c '[]
- WitAllInstancesCons :: c x => WitAllInstances c xs -> WitAllInstances c (x ': xs)
- 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
- cons :: x -> ContVec xs -> ContVec (x ': xs)
- consF :: f x -> ContVecF xs f -> ContVecF (x ': xs) f
- class (Arity n, Arity (HomList n a)) => HomArity n a where
- homInspect :: (Vector v a, HomArity (Dim v) a) => v a -> Fun (HomList (Dim v) a) r -> r
- homConstruct :: forall v a. (Vector v a, HomArity (Dim v) a) => Fun (HomList (Dim v) a) (v a)
- curryFun :: Fun (x ': xs) r -> x -> Fun xs r
- uncurryFun :: (x -> Fun xs r) -> Fun (x ': xs) r
- uncurryFun2 :: Arity xs => (x -> y -> Fun xs (Fun ys r)) -> Fun (x ': xs) (Fun (y ': ys) r)
- curryMany :: forall xs ys r. Arity xs => Fun (xs ++ ys) r -> Fun xs (Fun ys r)
- constFun :: Fun xs r -> Fun (x ': xs) r
- stepFun :: (Fun xs a -> Fun ys b) -> Fun (x ': xs) a -> Fun (x ': ys) b
- curryTFun :: TFun f (x ': xs) r -> f x -> TFun f xs r
- uncurryTFun :: (f x -> TFun f xs r) -> TFun f (x ': xs) r
- uncurryTFun2 :: (Arity xs, Arity ys) => (f x -> f y -> TFun f xs (TFun f ys r)) -> TFun f (x ': xs) (TFun f (y ': ys) r)
- shuffleTF :: forall f x xs r. Arity xs => (x -> TFun f xs r) -> TFun f xs (x -> r)
- concatF :: (Arity xs, Arity ys) => (a -> b -> c) -> Fun xs a -> Fun ys b -> Fun (xs ++ ys) c
- shuffleF :: forall x xs r. Arity xs => (x -> Fun xs r) -> Fun xs (x -> r)
- lensWorkerF :: forall f r x y xs. (Functor f, Arity xs) => (x -> f y) -> Fun (y ': xs) r -> Fun (x ': xs) (f r)
- class Arity n => Index n xs where
Types and type classes
Peano numbers
Successor of n
Instances
Arity n => Index Z (S n) | |
Arity n => Arity (S n) | |
(NatIso k ((-) n 1), (~) * (ToPeano ((-) n 1)) k, (~) * (ToPeano n) (S k), (~) Nat n ((+) 1 ((-) n 1))) => NatIso (S k) n | |
HomArity n a => HomArity (S n) a # | |
Index k n => Index (S k) (S n) | |
Index n xs => Index (S n) ((:) * x xs) # | |
type HomList α (S n) a # | |
type Add (S n) k | |
type Fn (S n) a b | |
type ValueAt (S n) ((:) * x xs) # | |
type NewElems (S n) ((:) * x xs) a # | |
Type level zero
Isomorphism between Peano numbers and Nats
class ((~) Nat (ToNat a) b, (~) * (ToPeano b) a) => NatIso a b #
Isomorphism between two representations of natural numbers
N-ary functions
type family Fn (as :: [*]) b #
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.
Type functions
data Proxy k t :: forall k. k -> * #
A concrete, poly-kinded proxy type
Constructors
Proxy |
Instances
Monad (Proxy *) | |
Functor (Proxy *) | |
Applicative (Proxy *) | |
Generic1 (Proxy *) | |
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) | |
type family Len (xs :: [α]) :: * #
Length of type list expressed as type level naturals from
fixed-vector
.
type family HomList n (a :: α) :: [α] #
Homogeneous type list with length n and element of type a. It
uses type level natural defined in fixed-vector
.
Type classes
class Arity (Len xs) => Arity xs where #
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.
Minimal complete definition
accum, apply, applyM, accumTy, applyTy, arity, witWrapped, witConcat, witNestedFun, witLenWrap
Methods
accum :: (forall a as. t (a ': as) -> a -> t as) -> (t '[] -> b) -> t xs -> Fn xs b #
Fold over N elements exposed as N-ary function.
apply :: (forall a as. t (a ': as) -> (a, t as)) -> t xs -> ContVec xs #
Apply values to N-ary function
applyM :: Monad m => (forall a as. t (a ': as) -> m (a, t as)) -> t xs -> 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 #
Analog of accum
applyTy :: (forall a as. t (a ': as) -> (f a, t as)) -> t xs -> ContVecF xs f #
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 #
witConcat :: Arity ys => WitConcat xs ys #
witNestedFun :: WitNestedFun xs ys r #
witLenWrap :: WitLenWrap f xs #
class Arity xs => ArityC c xs where #
Declares that every type in list satisfy constraint c
Minimal complete definition
Methods
witAllInstances :: WitAllInstances c xs #
class Arity (Elems v) => HVector v where #
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.
Methods
construct :: Fun (Elems v) v #
Function for constructing vector
construct :: (Generic v, GHVector (Rep v), GElems (Rep v) ~ Elems v) => Fun (Elems v) v #
Function for constructing vector
inspect :: v -> Fun (Elems v) a -> a #
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 #
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) # | |
(Unbox n a, HomArity n a) => HVector (Vec n a) # | |
(Storable 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 |
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) # | |
HVector (a, b, c, d, e, f, g, h) # | |
HVector (a, b, c, d, e, f, g, h, i) # | |
HVector (a, b, c, d, e, f, g, h, i, j) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) # | |
HVector (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) # | |
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) # | |
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) # | |
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) # | |
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') # | |
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') # | |
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') # | |
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') # | |
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') # | |
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') # | |
class Arity (ElemsF v) => HVectorF v where #
Type class for partially homogeneous vector where every element in the vector have same type constructor. Vector itself is parametrized by that constructor
Minimal complete definition
Witnesses
data WitWrapped f xs where #
Witness that observe fact that if we have instance Arity xs
than we have instance Arity (Wrap f xs)
.
Constructors
WitWrapped :: Arity (Wrap f xs) => WitWrapped f xs |
Witness that observe fact that (Arity xs, Arity ys)
implies
Arity (xs++ys)
data WitNestedFun xs ys r where #
Observes fact that Fn (xs++ys) r ~ Fn xs (Fn ys r)
Constructors
WitNestedFun :: Fn (xs ++ ys) r ~ Fn xs (Fn ys r) => WitNestedFun xs ys r |
data WitLenWrap f xs where #
Observe fact than Len xs ~ Len (Wrap f xs)
Constructors
WitLenWrap :: Len xs ~ Len (Wrap f xs) => WitLenWrap f xs |
data WitWrapIndex f n xs where #
Proofs for the indexing of wrapped type lists.
Constructors
WitWrapIndex :: (ValueAt n (Wrap f xs) ~ f (ValueAt n xs), Index n (Wrap f xs), Arity (Wrap f xs)) => WitWrapIndex f n xs |
data WitAllInstances c xs where #
Witness that all elements of type list satisfy predicate c
.
Constructors
WitAllInstancesNil :: WitAllInstances c '[] | |
WitAllInstancesCons :: c x => WitAllInstances c xs -> WitAllInstances c (x ': xs) |
CPS-encoded vector
CPS-encoded heterogeneous vector.
Constructors
ContVec | |
Fields
|
CPS-encoded partially heterogeneous vector.
toContVecF :: ContVec (Wrap f xs) -> ContVecF xs f #
Interop with homogeneous vectors
class (Arity n, Arity (HomList n a)) => HomArity n a where #
Conversion between homogeneous and heterogeneous N-ary functions.
Minimal complete definition
Methods
toHeterogeneous :: Fun n a r -> Fun (HomList n a) r #
Convert n-ary homogeneous function to heterogeneous.
toHomogeneous :: Fun (HomList n a) r -> Fun n a r #
Convert heterogeneous n-ary function to homogeneous.
homInspect :: (Vector v a, HomArity (Dim v) a) => v a -> Fun (HomList (Dim v) a) r -> r #
Default implementation of inspect
for homogeneous vector.
homConstruct :: forall v a. (Vector v a, HomArity (Dim v) a) => Fun (HomList (Dim v) a) (v a) #
Default implementation of construct
for homogeneous vector.
Operations of Fun
Primitives for Fun
uncurryFun :: (x -> Fun xs r) -> Fun (x ': xs) r #
Uncurry N-ary function.
curryMany :: forall xs ys r. Arity xs => Fun (xs ++ ys) r -> Fun xs (Fun ys r) #
Curry first n arguments of N-ary function.
stepFun :: (Fun xs a -> Fun ys b) -> Fun (x ': xs) a -> Fun (x ': ys) b #
Transform function but leave outermost parameter untouched.
Primitives for TFun
uncurryTFun :: (f x -> TFun f xs r) -> TFun f (x ': xs) r #
Uncurry single parameter
uncurryTFun2 :: (Arity xs, Arity ys) => (f x -> f y -> TFun f xs (TFun f ys r)) -> TFun f (x ': xs) (TFun f (y ': ys) r) #
Uncurry two parameters for nested TFun.
shuffleTF :: forall f x xs r. Arity xs => (x -> TFun f xs r) -> TFun f xs (x -> r) #
Move first argument of function to its result. This function is useful for implementation of lens.
More complicated functions
concatF :: (Arity xs, Arity ys) => (a -> b -> c) -> Fun xs a -> Fun ys b -> Fun (xs ++ ys) c #
Concatenate n-ary functions. This function combine results of both N-ary functions and merge their parameters into single list.
shuffleF :: forall x xs r. Arity xs => (x -> Fun xs r) -> Fun xs (x -> r) #
Move first argument of function to its result. This function is useful for implementation of lens.
lensWorkerF :: forall f r x y xs. (Functor f, Arity xs) => (x -> f y) -> Fun (y ': xs) r -> Fun (x ': xs) (f r) #
Helper for lens implementation.
class Arity n => Index n xs where #
Indexing of vectors
Minimal complete definition
getF, putF, lensF, lensChF, witWrapIndex
Associated Types
Type at position n
List of types with n'th element replaced by a.
Methods
getF :: n -> Fun xs (ValueAt n xs) #
Getter function for vectors
putF :: n -> ValueAt n xs -> Fun xs r -> Fun xs r #
Putter function. It applies value x
to n
th parameter of
function.
lensF :: (Functor f, v ~ ValueAt n xs) => n -> (v -> f v) -> Fun xs r -> Fun xs (f r) #
Helper for implementation of lens
lensChF :: Functor f => n -> (ValueAt n xs -> f a) -> Fun (NewElems n xs a) r -> Fun xs (f r) #
Helper for type-changing lens
witWrapIndex :: WitWrapIndex f n xs #