Copyright  (c) Artem Chirkin 

License  BSD3 
Safe Haskell  None 
Language  Haskell2010 
This module provides KnownDim
class that is similar to KnownNat
from TypeNats
,
but keeps Word
s instead of Natural
s;
Also it provides Dim
data type serving as a singleton
suitable for recovering an instance of the KnownDim
class.
A set of utility functions provide inference functionality, so
that KnownDim
can be preserved over some typelevel operations.
Provides a data type Dims ds
to keep dimension sizes
for multipledimensional data.
Higher indices go first, i.e. assumed enumeration
is i = i1*n1*n2*...*n(k1) + ... + i(k2)*n1*n2 + i(k1)*n1 + ik
This corresponds to rowfirst layout of matrices and multidimenional arrays.
Synopsis
 data Nat
 data XNat
 type XN = 'XN
 type N = 'N
 data DimType (d :: k) where
 class KnownDimType d where
 data DimKind (k :: Type) where
 class KnownDimKind k where
 data Dim (x :: k) where
 pattern D :: forall d. KnownDimType d => (KindOf d ~ Nat, KnownDim d) => Dim d
 pattern Dn :: forall d. KnownDimType d => forall (n :: Nat). d ~~ N n => Dim n > Dim d
 pattern Dx :: forall d. KnownDimType d => forall (m :: Nat) (n :: Nat). (d ~~ XN m, m <= n) => Dim n > Dim d
 pattern D0 :: forall (n :: Nat). () => n ~ 0 => Dim n
 pattern D1 :: forall (n :: Nat). () => n ~ 1 => Dim n
 pattern D2 :: forall (n :: Nat). () => n ~ 2 => Dim n
 pattern D3 :: forall (n :: Nat). () => n ~ 3 => Dim n
 pattern D4 :: forall (n :: Nat). () => n ~ 4 => Dim n
 pattern D5 :: forall (n :: Nat). () => n ~ 5 => Dim n
 pattern D6 :: forall (n :: Nat). () => n ~ 6 => Dim n
 pattern D7 :: forall (n :: Nat). () => n ~ 7 => Dim n
 pattern D8 :: forall (n :: Nat). () => n ~ 8 => Dim n
 pattern D9 :: forall (n :: Nat). () => n ~ 9 => Dim n
 pattern D10 :: forall (n :: Nat). () => n ~ 10 => Dim n
 pattern D11 :: forall (n :: Nat). () => n ~ 11 => Dim n
 pattern D12 :: forall (n :: Nat). () => n ~ 12 => Dim n
 pattern D13 :: forall (n :: Nat). () => n ~ 13 => Dim n
 pattern D14 :: forall (n :: Nat). () => n ~ 14 => Dim n
 pattern D15 :: forall (n :: Nat). () => n ~ 15 => Dim n
 pattern D16 :: forall (n :: Nat). () => n ~ 16 => Dim n
 pattern D17 :: forall (n :: Nat). () => n ~ 17 => Dim n
 pattern D18 :: forall (n :: Nat). () => n ~ 18 => Dim n
 pattern D19 :: forall (n :: Nat). () => n ~ 19 => Dim n
 pattern D20 :: forall (n :: Nat). () => n ~ 20 => Dim n
 pattern D21 :: forall (n :: Nat). () => n ~ 21 => Dim n
 pattern D22 :: forall (n :: Nat). () => n ~ 22 => Dim n
 pattern D23 :: forall (n :: Nat). () => n ~ 23 => Dim n
 pattern D24 :: forall (n :: Nat). () => n ~ 24 => Dim n
 pattern D25 :: forall (n :: Nat). () => n ~ 25 => Dim n
 type SomeDim = Dim (XN 0)
 class KnownDim n where
 withKnownXDim :: forall (d :: XNat) (rep :: RuntimeRep) (r :: TYPE rep). KnownDim d => ((KnownDim (DimBound d), ExactDim d, KnownDimType d, FixedDim d (DimBound d)) => r) > r
 class (KnownDimKind (KindOf d), KnownDimType d, KnownDim (DimBound d)) => BoundedDim d where
 minimalDim :: forall n. BoundedDim n => Dim n
 type family ExactDim (d :: k) :: Constraint where ...
 type family FixedDim (x :: XNat) (n :: Nat) :: Constraint where ...
 dimVal :: forall x. Dim x > Word
 dimVal' :: forall n. KnownDim n => Word
 typeableDim :: forall (n :: Nat). Typeable n => Dim n
 someDimVal :: Word > SomeDim
 sameDim :: forall (x :: Nat) (y :: Nat). Dim x > Dim y > Maybe (Dict (x ~ y))
 sameDim' :: forall (x :: Nat) (y :: Nat). (KnownDim x, KnownDim y) => Maybe (Dict (x ~ y))
 lessOrEqDim :: forall (x :: Nat) (y :: Nat). Dim x > Dim y > Maybe (Dict (x <= y))
 lessOrEqDim' :: forall (x :: Nat) (y :: Nat). (KnownDim x, KnownDim y) => Maybe (Dict (x <= y))
 compareDim :: forall (a :: Nat) (b :: Nat). Dim a > Dim b > SOrdering (CmpNat a b)
 compareDim' :: forall (a :: Nat) (b :: Nat). (KnownDim a, KnownDim b) => SOrdering (CmpNat a b)
 constrainBy :: forall x p y. BoundedDim x => p x > Dim y > Maybe (Dim x)
 relax :: forall (m :: Nat) (n :: Nat). (<=) m n => Dim (XN n) > Dim (XN m)
 plusDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (n + m)
 minusDim :: forall (n :: Nat) (m :: Nat). (<=) m n => Dim n > Dim m > Dim (n  m)
 minusDimM :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Maybe (Dim (n  m))
 timesDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (* n m)
 powerDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim ((^) n m)
 divDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Div n m)
 modDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Mod n m)
 log2Dim :: forall (n :: Nat). Dim n > Dim (Log2 n)
 minDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Min n m)
 maxDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Max n m)
 type family CmpNat (a :: Nat) (b :: Nat) :: Ordering where ...
 data SOrdering :: Ordering > Type where
 type family (a :: Nat) + (b :: Nat) :: Nat where ...
 type family (a :: Nat)  (b :: Nat) :: Nat where ...
 type family (a :: Nat) * (b :: Nat) :: Nat where ...
 type family (a :: Nat) ^ (b :: Nat) :: Nat where ...
 type (<=) (a :: Nat) (b :: Nat) = LE a b (CmpNat a b)
 type Min (a :: Nat) (b :: Nat) = Min' a b (CmpNat a b)
 type Max (a :: Nat) (b :: Nat) = Max' a b (CmpNat a b)
 type Dims = TypedList Dim :: [k] > Type
 data SomeDims = forall (ns :: [Nat]). SomeDims (Dims ns)
 class Dimensions ds where
 withKnownXDims :: forall (ds :: [XNat]) (rep :: RuntimeRep) (r :: TYPE rep). Dimensions ds => ((Dimensions (DimsBound ds), ExactDims ds, All KnownDimType ds, FixedDims ds (DimsBound ds)) => r) > r
 class (KnownDimKind (KindOfEl ds), All BoundedDim ds, RepresentableList ds, Dimensions (DimsBound ds), BoundedDimsTail ds) => BoundedDims ds where
 type family DimsBound (ds :: [k]) :: [Nat] where ...
 minimalDims :: forall ds. BoundedDims ds => Dims ds
 type family ExactDims (d :: [k]) :: Constraint where ...
 type family FixedDims (xns :: [XNat]) (ns :: [Nat]) :: Constraint where ...
 inferFixedDims :: forall (xns :: [XNat]) (ns :: [Nat]). All KnownDimType xns => Dims xns > Dims ns > Maybe (Dict (FixedDims xns ns))
 inferExactFixedDims :: forall (ds :: [XNat]). ExactDims ds => Dims (DimsBound ds) > Dict (All KnownDimType ds, FixedDims ds (DimsBound ds))
 data TypedList (f :: k > Type) (xs :: [k]) where
 pattern Dims :: forall ds. KnownDimKind (KindOfEl ds) => forall (ns :: [Nat]). (ds ~~ ns, Dimensions ns) => Dims ds
 pattern XDims :: forall ds. KnownDimKind (KindOfEl ds) => forall (ns :: [Nat]). FixedDims ds ns => Dims ns > Dims ds
 pattern KnownDims :: forall (ds :: [Nat]). () => (All KnownDim ds, All BoundedDim ds, RepresentableList ds, Dimensions ds) => Dims ds
 pattern U :: forall (k :: Type) (f :: k > Type) (xs :: [k]). () => xs ~ '[] => TypedList f xs
 pattern (:*) :: forall f xs. () => forall y ys. xs ~ (y ': ys) => f y > TypedList f ys > TypedList f xs
 pattern Empty :: forall (k :: Type) (f :: k > Type) (xs :: [k]). () => xs ~ '[] => TypedList f xs
 pattern TypeList :: forall xs. () => RepresentableList xs => TypeList xs
 pattern Cons :: forall f xs. () => forall y ys. xs ~ (y ': ys) => f y > TypedList f ys > TypedList f xs
 pattern Snoc :: forall f xs. () => forall sy y. SnocList sy y xs => TypedList f sy > f y > TypedList f xs
 pattern Reverse :: forall f xs. () => forall sx. ReverseList xs sx => TypedList f sx > TypedList f xs
 typeableDims :: forall (ds :: [Nat]). Typeable ds => Dims ds
 inferTypeableDims :: forall (ds :: [Nat]). Dims ds > Dict (Typeable ds)
 listDims :: forall xs. Dims xs > [Word]
 someDimsVal :: [Word] > SomeDims
 totalDim :: forall xs. Dims xs > Word
 totalDim' :: forall xs. Dimensions xs => Word
 sameDims :: forall (as :: [Nat]) (bs :: [Nat]). Dims as > Dims bs > Maybe (Dict (as ~ bs))
 sameDims' :: forall (as :: [Nat]) (bs :: [Nat]) (p :: [Nat] > Type) (q :: [Nat] > Type). (Dimensions as, Dimensions bs) => p as > q bs > Maybe (Dict (as ~ bs))
 inSpaceOf :: forall ds p q. p ds > q ds > p ds
 stripPrefixDims :: forall (xs :: [Nat]) (ys :: [Nat]). Dims xs > Dims ys > Maybe (Dims (StripPrefix xs ys))
 stripSuffixDims :: forall (xs :: [Nat]) (ys :: [Nat]). Dims xs > Dims ys > Maybe (Dims (StripSuffix xs ys))
 class RepresentableList xs where
 type TypeList = TypedList Proxy :: [k] > Type
 types :: forall f xs. TypedList f xs > TypeList xs
 order :: forall f xs. TypedList f xs > Dim (Length xs)
 order' :: forall xs. RepresentableList xs => Dim (Length xs)
 type KindOf (t :: k) = k
 type KindOfEl (ts :: [k]) = k
Dim
: a Nat
indexed dimension
Type level numbers that can be unknown.
(Kind) This is the kind of typelevel natural numbers.
Instances
Either known or unknown at compiletime natural number
Instances
KnownDimKind XNat Source #  
BoundedDims ('[] :: [XNat]) Source #  
KnownDim n => BoundedDim (N n :: XNat) Source #  
KnownDim m => BoundedDim (XN m :: XNat) Source #  
KnownDim n => KnownDim (N n :: XNat) Source #  
KnownDimType ('XN n :: XNat) Source #  
KnownDimType ('N n :: XNat) Source #  
(BoundedDim n, BoundedDims ns) => BoundedDims (n ': ns :: [XNat]) Source #  
Eq (Dim x) Source #  
Eq (Dims ds) Source #  
Ord (Dim x) Source #  
Ord (Dims ds) Source #  
type DimBound (N n :: XNat) Source #  
Defined in Numeric.Dimensions.Dim  
type DimBound ('XN m :: XNat) Source #  
Defined in Numeric.Dimensions.Dim 
data DimType (d :: k) where Source #
GADT to support KnownDimType
type class.
Find out if this type variable is a Nat
or XNat
,
and whether XNat
is of known or constrained type.
class KnownDimType d where Source #
Figure out whether the typelevel dimension is Nat
, or `N Nat`, or `XN Nat`.
Patternmatch against this to out the value (type) of the dim type variable.
Instances
KnownDimType (n :: Nat) Source #  
Defined in Numeric.Dimensions.Dim  
KnownDimType ('XN n :: XNat) Source #  
KnownDimType ('N n :: XNat) Source #  
Class (KnownDimKind k) (KnownDimType n) Source #  
Defined in Numeric.Dimensions.Dim cls :: KnownDimType n : KnownDimKind k # 
data DimKind (k :: Type) where Source #
GADT to support KnownDimKind
type class.
Match against its constructors to know if k
is Nat
or XNat
class KnownDimKind k where Source #
Instances
KnownDimKind Nat Source #  
KnownDimKind XNat Source #  
Class (KnownDimKind k) (KnownDimType n) Source #  
Defined in Numeric.Dimensions.Dim cls :: KnownDimType n : KnownDimKind k # 
Term level dimension
data Dim (x :: k) where Source #
Singleton type to store typelevel dimension value.
On the one hand, it can be used to let typeinference system know
relations between typelevel naturals.
On the other hand, this is just a newtype wrapper on the Word
type.
Usually, the type parameter of Dim
is either Nat
or XNat
.
If dimensionality of your data is known in advance, use Nat
;
if you know the size of some dimensions, but do not know the size
of others, use XNat
s to represent them.
pattern D :: forall d. KnownDimType d => (KindOf d ~ Nat, KnownDim d) => Dim d  Match against this pattern to bring 
pattern Dn :: forall d. KnownDimType d => forall (n :: Nat). d ~~ N n => Dim n > Dim d  Statically known 
pattern Dx :: forall d. KnownDimType d => forall (m :: Nat) (n :: Nat). (d ~~ XN m, m <= n) => Dim n > Dim d 

pattern D0 :: forall (n :: Nat). () => n ~ 0 => Dim n  Match 
pattern D1 :: forall (n :: Nat). () => n ~ 1 => Dim n  Match 
pattern D2 :: forall (n :: Nat). () => n ~ 2 => Dim n  Match 
pattern D3 :: forall (n :: Nat). () => n ~ 3 => Dim n  Match 
pattern D4 :: forall (n :: Nat). () => n ~ 4 => Dim n  Match 
pattern D5 :: forall (n :: Nat). () => n ~ 5 => Dim n  Match 
pattern D6 :: forall (n :: Nat). () => n ~ 6 => Dim n  Match 
pattern D7 :: forall (n :: Nat). () => n ~ 7 => Dim n  Match 
pattern D8 :: forall (n :: Nat). () => n ~ 8 => Dim n  Match 
pattern D9 :: forall (n :: Nat). () => n ~ 9 => Dim n  Match 
pattern D10 :: forall (n :: Nat). () => n ~ 10 => Dim n  Match 
pattern D11 :: forall (n :: Nat). () => n ~ 11 => Dim n  Match 
pattern D12 :: forall (n :: Nat). () => n ~ 12 => Dim n  Match 
pattern D13 :: forall (n :: Nat). () => n ~ 13 => Dim n  Match 
pattern D14 :: forall (n :: Nat). () => n ~ 14 => Dim n  Match 
pattern D15 :: forall (n :: Nat). () => n ~ 15 => Dim n  Match 
pattern D16 :: forall (n :: Nat). () => n ~ 16 => Dim n  Match 
pattern D17 :: forall (n :: Nat). () => n ~ 17 => Dim n  Match 
pattern D18 :: forall (n :: Nat). () => n ~ 18 => Dim n  Match 
pattern D19 :: forall (n :: Nat). () => n ~ 19 => Dim n  Match 
pattern D20 :: forall (n :: Nat). () => n ~ 20 => Dim n  Match 
pattern D21 :: forall (n :: Nat). () => n ~ 21 => Dim n  Match 
pattern D22 :: forall (n :: Nat). () => n ~ 22 => Dim n  Match 
pattern D23 :: forall (n :: Nat). () => n ~ 23 => Dim n  Match 
pattern D24 :: forall (n :: Nat). () => n ~ 24 => Dim n  Match 
pattern D25 :: forall (n :: Nat). () => n ~ 25 => Dim n  Match 
Instances
Eq (Dim n) Source #  
Eq (Dim x) Source #  
Eq (Dims ds) Source #  
Eq (Dims ds) Source #  
Typeable d => Data (Dim d) Source #  
Defined in Numeric.Dimensions.Dim gfoldl :: (forall d0 b. Data d0 => c (d0 > b) > d0 > c b) > (forall g. g > c g) > Dim d > c (Dim d) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (Dim d) # dataTypeOf :: Dim d > DataType # dataCast1 :: Typeable t => (forall d0. Data d0 => c (t d0)) > Maybe (c (Dim d)) # dataCast2 :: Typeable t => (forall d0 e. (Data d0, Data e) => c (t d0 e)) > Maybe (c (Dim d)) # gmapT :: (forall b. Data b => b > b) > Dim d > Dim d # gmapQl :: (r > r' > r) > r > (forall d0. Data d0 => d0 > r') > Dim d > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d0. Data d0 => d0 > r') > Dim d > r # gmapQ :: (forall d0. Data d0 => d0 > u) > Dim d > [u] # gmapQi :: Int > (forall d0. Data d0 => d0 > u) > Dim d > u # gmapM :: Monad m => (forall d0. Data d0 => d0 > m d0) > Dim d > m (Dim d) # gmapMp :: MonadPlus m => (forall d0. Data d0 => d0 > m d0) > Dim d > m (Dim d) # gmapMo :: MonadPlus m => (forall d0. Data d0 => d0 > m d0) > Dim d > m (Dim d) #  
Ord (Dim n) Source #  
Ord (Dim x) Source #  
Ord (Dims ds) Source #  
Ord (Dims ds) Source #  
BoundedDim x => Read (Dim x) Source #  
BoundedDims xs => Read (Dims xs) Source #  
Show (Dim x) Source #  
Show (Dims xs) Source #  
KnownDim d => Generic (Dim d) Source #  
type Rep (Dim d) Source #  
class KnownDim n where Source #
This class provides the Dim
associated with a typelevel natural.
Note, kind of the KnownDim
argument is usually Nat
, because
it is impossible to create a unique KnownDim (XN m)
instance.
Nevertheless, you can have KnownDim (N n)
, which is useful in some cases.
Get value of typelevel dim at runtime.
Note, this function is supposed to be used with TypeApplications
.
For example, you can type:
>>>
:set XTypeApplications
>>>
:set XDataKinds
>>>
:t dim @3
dim @3 :: Dim 3
>>>
:set XTypeOperators
>>>
:t dim @(13  6)
dim @(13  6) :: Dim 7
Instances
withKnownXDim :: forall (d :: XNat) (rep :: RuntimeRep) (r :: TYPE rep). KnownDim d => ((KnownDim (DimBound d), ExactDim d, KnownDimType d, FixedDim d (DimBound d)) => r) > r Source #
If you have KnownDim d
, then d
can only be Nat
or a known type of
XNat
(i.e. N n
).
This function assures the type checker that this is indeed the case.
class (KnownDimKind (KindOf d), KnownDimType d, KnownDim (DimBound d)) => BoundedDim d where Source #
Get a minimal or exact bound of a Dim
.
To satisfy the BoundedDim
means to be equal to N n
or be not less than XN m
.
type DimBound d :: Nat Source #
Minimal or exact bound of a Dim
.
Useful for indexing: it is safe to index something by an index less than
DimBound n
(for both Nat
and Xnat
indexed dims).
dimBound :: Dim (DimBound d) Source #
Get such a minimal Dim (DimBound n)
, that Dim n
is guaranteed
to be not less than dimBound
if n ~ XN a
,
otherwise, the return Dim
is the same as n
.
constrainDim :: forall y. Dim y > Maybe (Dim d) Source #
If the runtime value of Dim y
satisfies dimBound
x,
then coerce to
Dim x. Otherwise, return
Nothing@.
To satisfy the dimBound
means to be equal to N n
or be not less than XN m
.
minimalDim :: forall n. BoundedDim n => Dim n Source #
Returns the minimal Dim
that satisfies the BoundedDim
constraint
(this is the exact dim
for Nat
s and the minimal bound for XNat
s).
type family ExactDim (d :: k) :: Constraint where ... Source #
This is either Nat
, or a known XNat
(i.e. N n
).
type family FixedDim (x :: XNat) (n :: Nat) :: Constraint where ... Source #
Constraints given by an XNat type on possible values of a Nat hidden inside.
typeableDim :: forall (n :: Nat). Typeable n => Dim n Source #
Construct a Dim n
if there is an instance of Typeable n
around.
Note: we can do this only for Nat
indexed dim, because the type XN m
does not have enough information to create a dim at runtime.
someDimVal :: Word > SomeDim Source #
Similar to someNatVal
from TypeNats
.
sameDim :: forall (x :: Nat) (y :: Nat). Dim x > Dim y > Maybe (Dict (x ~ y)) Source #
We either get evidence that this function was instantiated with the same typelevel numbers, or Nothing.
Note, this function works on Nat
indexed dimensions only,
because Dim (XN x)
does not have runtime evidence to infer x
and `KnownDim x` does not imply `KnownDim (XN x)`.
sameDim' :: forall (x :: Nat) (y :: Nat). (KnownDim x, KnownDim y) => Maybe (Dict (x ~ y)) Source #
We either get evidence that this function was instantiated with the same typelevel numbers, or Nothing.
lessOrEqDim :: forall (x :: Nat) (y :: Nat). Dim x > Dim y > Maybe (Dict (x <= y)) Source #
We either get evidence that x
is not greater than y
, or Nothing.
lessOrEqDim' :: forall (x :: Nat) (y :: Nat). (KnownDim x, KnownDim y) => Maybe (Dict (x <= y)) Source #
We either get evidence that x
is not greater than y
, or Nothing.
compareDim' :: forall (a :: Nat) (b :: Nat). (KnownDim a, KnownDim b) => SOrdering (CmpNat a b) Source #
constrainBy :: forall x p y. BoundedDim x => p x > Dim y > Maybe (Dim x) Source #
constrainDim
with explicitlypassed constraining Dim
to avoid AllowAmbiguousTypes
.
relax :: forall (m :: Nat) (n :: Nat). (<=) m n => Dim (XN n) > Dim (XN m) Source #
Decrease minimum allowed size of a Dim (XN x)
.
Simple Dim arithmetics
plusDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (n + m) Source #
Same as `Prelude.(+)`.
Patternmatching against the result would produce the evindence
KnownDim (n + m)
.
minusDim :: forall (n :: Nat) (m :: Nat). (<=) m n => Dim n > Dim m > Dim (n  m) Source #
Same as `Prelude.()`.
Patternmatching against the result would produce the evindence
KnownDim (n  m)
.
minusDimM :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Maybe (Dim (n  m)) Source #
Similar to minusDim
, but returns Nothing
if the result would be negative.
Patternmatching against the result would produce the evindence
KnownDim (n  m)
.
timesDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (* n m) Source #
Same as `Prelude.(*)`.
Patternmatching against the result would produce the evindence
KnownDim (n * m)
.
powerDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim ((^) n m) Source #
Same as `Prelude.(^)`.
Patternmatching against the result would produce the evindence
KnownDim (n ^ m)
.
divDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Div n m) Source #
Same as div
.
Patternmatching against the result would produce the evindence
KnownDim (Div n m)
.
modDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Mod n m) Source #
Same as mod
.
Patternmatching against the result would produce the evindence
KnownDim (Mod n m)
.
log2Dim :: forall (n :: Nat). Dim n > Dim (Log2 n) Source #
Returns log base 2 (round down).
Patternmatching against the result would produce the evindence
KnownDim (Log2 n)
.
minDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Min n m) Source #
Same as min
.
Patternmatching against the result would produce the evindence
KnownDim (Min n m)
.
maxDim :: forall (n :: Nat) (m :: Nat). Dim n > Dim m > Dim (Max n m) Source #
Same as max
.
Patternmatching against the result would produce the evindence
KnownDim (Max n m)
.
Reexport part of
Lits
for convenience
type family CmpNat (a :: Nat) (b :: Nat) :: Ordering where ... #
Comparison of typelevel naturals, as a function.
Since: base4.7.0.0
data SOrdering :: Ordering > Type where Source #
Singletonstyle version of Ordering
.
Patternmatch againts its constructor to witness the result of
typelevel comparison.
type family (a :: Nat) + (b :: Nat) :: Nat where ... infixl 6 #
Addition of typelevel naturals.
Since: base4.7.0.0
type family (a :: Nat)  (b :: Nat) :: Nat where ... infixl 6 #
Subtraction of typelevel naturals.
Since: base4.7.0.0
type family (a :: Nat) * (b :: Nat) :: Nat where ... infixl 7 #
Multiplication of typelevel naturals.
Since: base4.7.0.0
type family (a :: Nat) ^ (b :: Nat) :: Nat where ... infixr 8 #
Exponentiation of typelevel naturals.
Since: base4.7.0.0
type (<=) (a :: Nat) (b :: Nat) = LE a b (CmpNat a b) Source #
Comparison of typelevel naturals, as a constraint.
type Min (a :: Nat) (b :: Nat) = Min' a b (CmpNat a b) Source #
Miminum among two typelevel naturals.
type Max (a :: Nat) (b :: Nat) = Max' a b (CmpNat a b) Source #
Maximum among two typelevel naturals.
Dims
: a list of dimensions
Same as SomeNat, but for Dimensions: Hide all information about Dimensions inside
class Dimensions ds where Source #
Put runtime evidence of Dims
value inside function constraints.
Similar to KnownDim
or KnownNat
, but for lists of numbers.
Note, kind of the Dimensions
list is usually Nat
, restricted by
KnownDim
being also Nat
indexed
(it is impossible to create a unique KnownDim (XN m)
instance).
Nevertheless, you can have KnownDim (N n)
, which is useful in some cases.
Get dimensionality of a space at runtime,
represented as a list of Dim
.
Note, this function is supposed to be used with TypeApplications
.
For example, you can type:
>>>
:set XTypeApplications
>>>
:set XDataKinds
>>>
:t dims @'[17, 12]
dims @'[17, 12] :: Dims '[17, 12]
>>>
:t dims @'[]
dims @'[] :: Dims '[]
>>>
:t dims @(Tail '[3,2,5,7])
dims @(Tail '[3,2,5,7]) :: Dims '[2, 5, 7]
Instances
Dimensions ('[] :: [k]) Source #  
Defined in Numeric.Dimensions.Dim  
(KnownDim d, Dimensions ds) => Dimensions (d ': ds :: [k]) Source #  
Defined in Numeric.Dimensions.Dim 
withKnownXDims :: forall (ds :: [XNat]) (rep :: RuntimeRep) (r :: TYPE rep). Dimensions ds => ((Dimensions (DimsBound ds), ExactDims ds, All KnownDimType ds, FixedDims ds (DimsBound ds)) => r) > r Source #
If you have Dimensions ds
, then ds
can only be [Nat]
or a known type of
[XNa]t
(i.e. all N n
).
This function assures the type checker that this is indeed the case.
class (KnownDimKind (KindOfEl ds), All BoundedDim ds, RepresentableList ds, Dimensions (DimsBound ds), BoundedDimsTail ds) => BoundedDims ds where Source #
Get a minimal or exact bound of Dims
.
This is a plural form of BoundedDim
.
BoundedDims
is a somewhat weaker form of Dimensions
:
 It is defined for both
[Nat]
and[XNat]
;  Instance of
Dimensions ds
always impliesBoundedDims ds
.
BoundedDims
is a powerful inference tool:
its instances do not require much, but it provides a lot via the superclass
constraints.
dimsBound :: Dims (DimsBound ds) Source #
Plural form for dimBound
constrainDims :: forall ys. Dims ys > Maybe (Dims ds) Source #
Plural form for constrainDim
.
Given a Dims ys
, test if its runtime value satisfies constraints imposed by
BoundedDims xs
, and returns it back coerced to Dims xs
on success.
This function allows to guess safely individual dimension values,
as well as the length of the dimension list.
It returns Nothing
if xs
and ys
have different length or if any
of the values in ys
are less than the corresponding values of xs
.
Instances
Dimensions ns => BoundedDims (ns :: [Nat]) Source #  
BoundedDims ('[] :: [XNat]) Source #  
(BoundedDim n, BoundedDims ns) => BoundedDims (n ': ns :: [XNat]) Source #  
type family DimsBound (ds :: [k]) :: [Nat] where ... Source #
Minimal or exact bound of Dims
.
This is a plural form of DimBound
.
minimalDims :: forall ds. BoundedDims ds => Dims ds Source #
Minimal runtime Dims ds
value that satifies the constraints imposed by
the type signature of Dims ds
(this is the exact dims
for Nat
s and the minimal bound for XNat
s).
type family ExactDims (d :: [k]) :: Constraint where ... Source #
Every dim in a list is either Nat
, or a known XNat
(i.e. N n
).
type family FixedDims (xns :: [XNat]) (ns :: [Nat]) :: Constraint where ... Source #
Constrain Nat
dimensions hidden behind XNat
s.
This is a link connecting the two types of typelevel dims;
you often need it to convert Dims
, Idxs
, and data.
inferFixedDims :: forall (xns :: [XNat]) (ns :: [Nat]). All KnownDimType xns => Dims xns > Dims ns > Maybe (Dict (FixedDims xns ns)) Source #
Try to instantiate the FixedDims
constraint given two Dims
lists.
The first Dims
is assumed to be the output of minimalDims
,
i.e. listDims xns == toList (listDims xns)
.
If you input a list that is not equal to its typelevel DimsBound
,
you will just have a lower chance to get Just Dict
result.
inferExactFixedDims :: forall (ds :: [XNat]). ExactDims ds => Dims (DimsBound ds) > Dict (All KnownDimType ds, FixedDims ds (DimsBound ds)) Source #
Infer FixedDims
if you know that all of dims are exact (d ~ N n
).
This function is totally safe and faithful.
data TypedList (f :: k > Type) (xs :: [k]) where Source #
Typeindexed list
pattern Dims :: forall ds. KnownDimKind (KindOfEl ds) => forall (ns :: [Nat]). (ds ~~ ns, Dimensions ns) => Dims ds 

pattern XDims :: forall ds. KnownDimKind (KindOfEl ds) => forall (ns :: [Nat]). FixedDims ds ns => Dims ns > Dims ds 

pattern KnownDims :: forall (ds :: [Nat]). () => (All KnownDim ds, All BoundedDim ds, RepresentableList ds, Dimensions ds) => Dims ds 

pattern U :: forall (k :: Type) (f :: k > Type) (xs :: [k]). () => xs ~ '[] => TypedList f xs  Zerolength type list 
pattern (:*) :: forall f xs. () => forall y ys. xs ~ (y ': ys) => f y > TypedList f ys > TypedList f xs infixr 5  Constructing a typeindexed list 
pattern Empty :: forall (k :: Type) (f :: k > Type) (xs :: [k]). () => xs ~ '[] => TypedList f xs  Zerolength type list; synonym to 
pattern TypeList :: forall xs. () => RepresentableList xs => TypeList xs  Pattern matching against this causes 
pattern Cons :: forall f xs. () => forall y ys. xs ~ (y ': ys) => f y > TypedList f ys > TypedList f xs  Constructing a typeindexed list in the canonical way 
pattern Snoc :: forall f xs. () => forall sy y. SnocList sy y xs => TypedList f sy > f y > TypedList f xs  Constructing a typeindexed list from the other end 
pattern Reverse :: forall f xs. () => forall sx. ReverseList xs sx => TypedList f sx > TypedList f xs  Reverse a typed list 
Instances
(RepresentableList xs, All Bounded xs) => Bounded (Tuple xs) Source #  
(RepresentableList xs, All Bounded xs) => Bounded (Tuple xs) Source #  
All Eq xs => Eq (Tuple xs) Source #  
All Eq xs => Eq (Tuple xs) Source #  
(All Eq xs, All Ord xs) => Ord (Tuple xs) Source #  Lexicorgaphic ordering; same as normal Haskell lists. 
Defined in Numeric.Tuple.Strict  
(All Eq xs, All Ord xs) => Ord (Tuple xs) Source #  Lexicorgaphic ordering; same as normal Haskell lists. 
Defined in Numeric.Tuple.Lazy  
(All Read xs, RepresentableList xs) => Read (Tuple xs) Source #  
(All Read xs, RepresentableList xs) => Read (Tuple xs) Source #  
All Show xs => Show (Tuple xs) Source #  
All Show xs => Show (Tuple xs) Source #  
All Semigroup xs => Semigroup (Tuple xs) Source #  
All Semigroup xs => Semigroup (Tuple xs) Source #  
(RepresentableList xs, All Semigroup xs, All Monoid xs) => Monoid (Tuple xs) Source #  
(RepresentableList xs, All Semigroup xs, All Monoid xs) => Monoid (Tuple xs) Source #  
BoundedDims ds => Bounded (Idxs ds) Source #  
Dimensions ds => Enum (Idxs ds) Source # 

Eq (Dims ds) Source #  
Eq (Dims ds) Source #  
Eq (Idxs xs) Source #  
Ord (Dims ds) Source #  
Ord (Dims ds) Source #  
Ord (Idxs xs) Source #  Compare indices by their importance in lexicorgaphic order from the first dimension to the last dimension (the first dimension is the most significant one). Literally, compare a b = compare (listIdxs a) (listIdxs b) This is the same sort == sortOn fromEnum 
BoundedDims xs => Read (Dims xs) Source #  
BoundedDims xs => Read (Idxs xs) Source #  
Show (Dims xs) Source #  
Show (Idxs xs) Source #  
(Typeable k, Typeable f, Typeable xs, All Data (Map f xs)) => Data (TypedList f xs) Source #  Termlevel structure of a 
Defined in Numeric.TypedList gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > TypedList f xs > c (TypedList f xs) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (TypedList f xs) # toConstr :: TypedList f xs > Constr # dataTypeOf :: TypedList f xs > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (TypedList f xs)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (TypedList f xs)) # gmapT :: (forall b. Data b => b > b) > TypedList f xs > TypedList f xs # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > TypedList f xs > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > TypedList f xs > r # gmapQ :: (forall d. Data d => d > u) > TypedList f xs > [u] # gmapQi :: Int > (forall d. Data d => d > u) > TypedList f xs > u # gmapM :: Monad m => (forall d. Data d => d > m d) > TypedList f xs > m (TypedList f xs) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > TypedList f xs > m (TypedList f xs) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > TypedList f xs > m (TypedList f xs) #  
Generic (TypedList f xs) Source #  
type Rep (TypedList f xs) Source #  
Defined in Numeric.TypedList 
typeableDims :: forall (ds :: [Nat]). Typeable ds => Dims ds Source #
Construct a Dims ds
if there is an instance of Typeable ds
around.
inferTypeableDims :: forall (ds :: [Nat]). Dims ds > Dict (Typeable ds) Source #
Dims (ds :: [Nat])
is always Typeable
.
listDims :: forall xs. Dims xs > [Word] Source #
O(1)
Convert Dims xs
to a plain haskell list of dimension sizes.
Note, for XNat
indexed list it returns actual content dimensions,
not the constraint numbers (XN m
)
someDimsVal :: [Word] > SomeDims Source #
Convert a plain haskell list of dimension sizes into an unknown
typelevel dimensionality O(1)
.
totalDim' :: forall xs. Dimensions xs => Word Source #
Product of all dimension sizes O(Length xs)
.
sameDims :: forall (as :: [Nat]) (bs :: [Nat]). Dims as > Dims bs > Maybe (Dict (as ~ bs)) Source #
We either get evidence that this function was instantiated with the
same typelevel Dimensions, or Nothing
O(Length xs)
.
sameDims' :: forall (as :: [Nat]) (bs :: [Nat]) (p :: [Nat] > Type) (q :: [Nat] > Type). (Dimensions as, Dimensions bs) => p as > q bs > Maybe (Dict (as ~ bs)) Source #
We either get evidence that this function was instantiated with the
same typelevel Dimensions, or Nothing
O(Length xs)
.
stripPrefixDims :: forall (xs :: [Nat]) (ys :: [Nat]). Dims xs > Dims ys > Maybe (Dims (StripPrefix xs ys)) Source #
Drop the given prefix from a Dims list. It returns Nothing if the list did not start with the prefix given, or Just the Dims after the prefix, if it does.
stripSuffixDims :: forall (xs :: [Nat]) (ys :: [Nat]). Dims xs > Dims ys > Maybe (Dims (StripSuffix xs ys)) Source #
Drop the given suffix from a Dims list. It returns Nothing if the list did not end with the suffix given, or Just the Dims before the suffix, if it does.
Reexport type list
class RepresentableList xs where Source #
Representable type lists. Allows getting type information about list structure at runtime.
Instances
RepresentableList ('[] :: [k]) Source #  
Defined in Numeric.TypedList  
RepresentableList xs => RepresentableList (x ': xs :: [k]) Source #  
Defined in Numeric.TypedList 
types :: forall f xs. TypedList f xs > TypeList xs Source #
Get a constructible TypeList
from any other TypedList
;
Pattern matching agains the result brings RepresentableList
constraint
into the scope:
case types ts of TypeList > ...
order :: forall f xs. TypedList f xs > Dim (Length xs) Source #
Return the number of elements in a TypedList
(same as length
).
order' :: forall xs. RepresentableList xs => Dim (Length xs) Source #
Return the number of elements in a type list xs
bound by a constraint
RepresentableList xs
(same as order
, but takes no value arguments).