Safe Haskell | None |
---|---|
Language | Haskell98 |
- type family Fn (f :: α -> *) (as :: [α]) b where ...
- type Fun = TFun Identity
- newtype TFun f as b = TFun {}
- data Proxy k (t :: k) :: forall k. k -> * = Proxy
- type family (xs :: [α]) ++ (ys :: [α]) :: [α] where ...
- type family Len (xs :: [α]) :: PeanoNum where ...
- type family HomList (n :: PeanoNum) (a :: α) :: [α] where ...
- class Arity (xs :: [α]) where
- class Arity xs => ArityC c xs where
- class Arity (Elems v) => HVector v where
- tupleSize :: forall v proxy. HVector v => proxy v -> Int
- class Arity (ElemsF v) => HVectorF (v :: (α -> *) -> *) where
- type ElemsF v :: [α]
- tupleSizeF :: forall v f proxy. HVectorF v => proxy (v f) -> Int
- type ContVec xs = ContVecF xs Identity
- newtype ContVecF (xs :: [α]) (f :: α -> *) = ContVecF {
- runContVecF :: forall r. TFun f xs r -> r
- cons :: x -> ContVec xs -> ContVec (x ': xs)
- consF :: f x -> ContVecF xs f -> ContVecF (x ': xs) f
- class (ArityPeano n, Arity (HomList n a)) => HomArity n a where
- homInspect :: (Vector v a, HomArity (Peano (Dim v)) a) => v a -> Fun (HomList (Peano (Dim v)) a) r -> r
- homConstruct :: forall v a. (Vector v a, HomArity (Peano (Dim v)) a) => Fun (HomList (Peano (Dim v)) a) (v a)
- curryFun :: Fun (x ': xs) r -> x -> Fun xs r
- uncurryFun :: (x -> Fun xs r) -> Fun (x ': xs) r
- uncurryMany :: forall xs ys r. Arity xs => Fun xs (Fun ys r) -> Fun (xs ++ 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
- constTFun :: TFun f xs r -> TFun f (x ': xs) r
- curryTFun :: TFun f (x ': xs) r -> f x -> TFun f xs r
- uncurryTFun :: (f x -> TFun f xs r) -> TFun f (x ': xs) r
- shuffleTF :: forall f x xs r. Arity xs => (x -> TFun f xs r) -> TFun f xs (x -> r)
- stepTFun :: (TFun f xs a -> TFun f ys b) -> TFun f (x ': xs) a -> TFun f (x ': ys) b
- concatF :: (Arity xs, Arity ys) => (a -> b -> c) -> Fun xs a -> Fun ys b -> Fun (xs ++ ys) c
- lensWorkerF :: forall f r x y xs. (Functor f, Arity xs) => (x -> f y) -> Fun (y ': xs) r -> Fun (x ': xs) (f r)
- lensWorkerTF :: forall f g r x y xs. (Functor f, Arity xs) => (g x -> f (g y)) -> TFun g (y ': xs) r -> TFun g (x ': xs) (f r)
- class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where
Types and type classes
N-ary functions
type family Fn (f :: α -> *) (as :: [α]) b where ... Source #
Type family for N-ary function. Types of function parameters are encoded as the list of types.
type Fun = TFun Identity Source #
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 :: k) :: forall k. k -> * #
A concrete, poly-kinded proxy type
Generic1 k (Proxy k) | |
Monad (Proxy *) | Since: 4.7.0.0 |
Functor (Proxy *) | Since: 4.7.0.0 |
Applicative (Proxy *) | Since: 4.7.0.0 |
Foldable (Proxy *) | Since: 4.7.0.0 |
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 *) | Since: 4.9.0.0 |
MonadPlus (Proxy *) | Since: 4.9.0.0 |
NFData1 (Proxy *) | Since: 1.4.3.0 |
Vector (Proxy *) a | |
Bounded (Proxy k t) | |
Enum (Proxy k s) | Since: 4.7.0.0 |
Eq (Proxy k s) | Since: 4.7.0.0 |
Ord (Proxy k s) | Since: 4.7.0.0 |
Read (Proxy k s) | Since: 4.7.0.0 |
Show (Proxy k s) | Since: 4.7.0.0 |
Ix (Proxy k s) | Since: 4.7.0.0 |
Generic (Proxy k t) | |
Semigroup (Proxy k s) | Since: 4.9.0.0 |
Monoid (Proxy k s) | Since: 4.7.0.0 |
NFData (Proxy k a) | Since: 1.4.0.0 |
type Rep1 k (Proxy k) | |
type Dim (Proxy *) | |
type Rep (Proxy k t) | |
type family Len (xs :: [α]) :: PeanoNum where ... Source #
Length of type list expressed as type level naturals from
fixed-vector
.
type family HomList (n :: PeanoNum) (a :: α) :: [α] where ... Source #
Homogeneous type list with length n and element of type a. It
uses type level natural defined in fixed-vector
.
Type classes
class 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) -> f a -> t as) | Step function. Applies element to accumulator. |
-> (t '[] -> b) | Extract value from accumulator. |
-> t xs | Initial state. |
-> TFun f xs b |
Fold over N elements exposed as N-ary function.
:: (forall a as. t (a ': as) -> (f a, t as)) | Extract value to be applied to function. |
-> t xs | Initial state. |
-> ContVecF xs f |
Apply values to N-ary function
Size of type list as integer.
class Arity xs => ArityC c xs where Source #
:: proxy c | |
-> (forall a as. c a => t (a ': as) -> f a -> t as) | Step function. Applies element to accumulator. |
-> (t '[] -> b) | Extract value from accumulator. |
-> t xs | Initial state. |
-> TFun f xs b |
:: proxy c | |
-> (forall a as. c a => t (a ': as) -> (f a, t as)) | Extract value to be applied to function. |
-> t xs | Initial state. |
-> ContVecF xs f |
Apply values to N-ary function
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 # | |
HVector (a, b, c) Source # | |
Arity * xs => HVector (ContVecF * xs Identity) 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
CPS-encoded vector
newtype ContVecF (xs :: [α]) (f :: α -> *) Source #
CPS-encoded partially heterogeneous vector.
ContVecF | |
|
Interop with homogeneous vectors
class (ArityPeano n, Arity (HomList n a)) => HomArity n a where Source #
Conversion between homogeneous and heterogeneous N-ary functions.
homInspect :: (Vector v a, HomArity (Peano (Dim v)) a) => v a -> Fun (HomList (Peano (Dim v)) a) r -> r Source #
Default implementation of inspect
for homogeneous vector.
homConstruct :: forall v a. (Vector v a, HomArity (Peano (Dim v)) a) => Fun (HomList (Peano (Dim v)) a) (v a) Source #
Default implementation of construct
for homogeneous vector.
Operations of Fun
Primitives for Fun
uncurryFun :: (x -> Fun xs r) -> Fun (x ': xs) r Source #
Uncurry N-ary function.
uncurryMany :: forall xs ys r. Arity xs => Fun xs (Fun ys r) -> Fun (xs ++ ys) r Source #
Conversion function
curryMany :: forall xs ys r. Arity xs => Fun (xs ++ ys) r -> Fun xs (Fun ys r) Source #
Curry first n arguments of N-ary function.
Primitives for TFun
constTFun :: TFun f xs r -> TFun f (x ': xs) r Source #
Add one parameter to function which is ignored.
uncurryTFun :: (f x -> TFun f xs r) -> TFun f (x ': xs) r Source #
Uncurry single parameter
shuffleTF :: forall f x xs r. Arity xs => (x -> TFun f xs r) -> TFun f xs (x -> r) Source #
Move first argument of function to its result. This function is useful for implementation of lens.
stepTFun :: (TFun f xs a -> TFun f ys b) -> TFun f (x ': xs) a -> TFun f (x ': ys) b Source #
Transform function but leave outermost parameter untouched.
More complicated functions
concatF :: (Arity xs, Arity ys) => (a -> b -> c) -> Fun xs a -> Fun ys b -> Fun (xs ++ ys) c Source #
Concatenate n-ary functions. This function combine results of both N-ary functions and merge their parameters into single list.
lensWorkerF :: forall f r x y xs. (Functor f, Arity xs) => (x -> f y) -> Fun (y ': xs) r -> Fun (x ': xs) (f r) Source #
Helper for lens implementation.
lensWorkerTF :: forall f g r x y xs. (Functor f, Arity xs) => (g x -> f (g y)) -> TFun g (y ': xs) r -> TFun g (x ': xs) (f r) Source #
Helper for lens implementation.
class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where Source #
Indexing of vectors
type ValueAt n xs :: * Source #
Type at position n
type NewElems n xs a :: [*] Source #
List of types with n'th element replaced by a.
getF :: proxy n -> Fun xs (ValueAt n xs) Source #
Getter function for vectors
putF :: proxy n -> ValueAt n xs -> Fun xs r -> Fun xs r Source #
Putter function. It applies value x
to n
th parameter of
function.
lensF :: (Functor f, v ~ ValueAt n xs) => proxy n -> (v -> f v) -> Fun xs r -> Fun xs (f r) Source #
Helper for implementation of lens
lensChF :: Functor f => proxy n -> (ValueAt n xs -> f a) -> Fun (NewElems n xs a) r -> Fun xs (f r) Source #
Helper for type-changing lens