Safe Haskell | None |
---|---|
Language | Haskell2010 |
The indices supplied by this module are static type and value-level linked lists. Since their type gives us information about them, recursion on indices can be unrolled easily.
Indices look like x:.y:.Z :: i:.j:.Z
. The value is the actual index used,
and the type is the upper-bound on that index.
For instance, one index of a 4x4 matrix is 2:.2:.Z :: 3:.3:.Z
, and
another index for a 1024x1024x1024 cube is
512:.512:.512:.Z :: 1024:.1024:.1024:.Z
- class Ord n => Dim n where
- zero :: Dim a => a
- class Rank a b where
- setBound :: a -> b
- data a :. b = !Int :. !b
- data Z = Z
- data Mode :: * -> * where
- roll :: Dim a => Proxy a -> Mode a
- unroll :: Ranged a => Proxy a -> Mode a
- modeProxy :: Mode a -> Proxy a
- foldlRange :: Mode n -> (b -> n -> b) -> b -> b
- foldrRange :: Mode n -> (n -> b -> b) -> b -> b
- withRange :: Applicative m => Mode a -> (a -> m ()) -> m ()
- foldlRangeIndices :: Mode n -> (b -> Int -> b) -> b -> b
- foldrRangeIndices :: Mode n -> (Int -> b -> b) -> b -> b
- withRangeIndices :: Applicative m => Mode n -> (Int -> m ()) -> m ()
- class (Dim n, Range (ToPeano (Size n))) => Ranged n
- type family InRange a b :: Bool
- class Range n
- data Peano
- type family ToPeano n :: Peano
- type family Size dim :: Nat
- bounds :: (Dim a, Bounded a) => Proxy a -> (a, a)
- range :: Mode n -> [n]
- dimHead :: KnownNat x => (x :. xs) -> Int
- dimTail :: (x :. xs) -> xs
- pdimHead :: KnownNat x => proxy (x :. xs) -> Int
- pdimTail :: proxy (x :. xs) -> Proxy xs
- cnat :: KnownNat n => proxy (n :: Nat) -> Int
- type family And a b :: Bool
- dim :: QuasiQuoter
- dimu :: QuasiQuoter
- dimr :: QuasiQuoter
- module Data.Proxy
Core
class Ord n => Dim n where Source
each, rank, size, reflect', next, prev, toIndex, fromIndex', correct, correctOnce, lastDim, zipDims, unsafeZipDims, mapDim, unsafeMapDim
Index constructor, analogous to :
The Applicative
and Monad
instances multiply in their bind operations,
and their 'return'/'pure' creates an index whose first dimension is 1.
KnownNat s => Monad ((:.) Nat s) | |
Functor ((:.) k a) | |
KnownNat s => Applicative ((:.) Nat s) | |
Foldable ((:.) k a) | |
Traversable ((:.) k a) | |
Dim ((:.) k x xs) => Bounded ((:.) k x xs) | |
Dim ((:.) k x xs) => Enum ((:.) k x xs) | |
Eq b => Eq ((:.) k a b) | |
(Integral xs, Dim ((:.) k x xs), Enum ((:.) k x xs)) => Integral ((:.) k x xs) | |
Dim ((:.) k x xs) => Num ((:.) k x xs) | |
Ord b => Ord ((:.) k a b) | |
Read b => Read ((:.) k a b) | |
(Num ((:.) k x xs), Dim ((:.) k x xs)) => Real ((:.) k x xs) | |
Show b => Show ((:.) k a b) | |
(Ranged ((:.) k x xs), Num xs) => Ix ((:.) k x xs) | The indices in an Ix instance are always bound by (0, t), where t is the type of the index. |
Generic ((:.) k a b) | |
(Dim ((:.) k x xs), Monoid xs) => Monoid ((:.) k x xs) | |
(KnownNat x, Dim xs) => Dim ((:.) Nat x xs) | |
Rank xs ys => Rank ((:.) k x xs) ((:.) k y ys) | Rank |
type Rep ((:.) k a b) |
The zero index, used to end indices, just as '[]' ends a list.
Selecting whether to unroll loops
data Mode :: * -> * where Source
Select whether to generate an unrolled loop or just the loop at compile-time.
Using ranges
foldlRange :: Mode n -> (b -> n -> b) -> b -> b Source
Lazy right fold over a range.
foldrRange :: Mode n -> (n -> b -> b) -> b -> b Source
Lazy right fold over a range.
withRange :: Applicative m => Mode a -> (a -> m ()) -> m () Source
Compute something from a range
Over Int
indices
foldlRangeIndices :: Mode n -> (b -> Int -> b) -> b -> b Source
Strict left fold over the raw Int
indices under a range
foldrRangeIndices :: Mode n -> (Int -> b -> b) -> b -> b Source
Lazy right fold over the raw Int
indices under a range
withRangeIndices :: Applicative m => Mode n -> (Int -> m ()) -> m () Source
Compute something using the raw indices under a range
Range types
class (Dim n, Range (ToPeano (Size n))) => Ranged n Source
Types that support static range operations
swithRange_, sfoldrRange_, sfoldlRange_, swithRangeIndices_, sfoldrRangeIndices_, sfoldlRangeIndices_
Utility
bounds :: (Dim a, Bounded a) => Proxy a -> (a, a) Source
Create a bound for use with e.g. "Data.Array.array"
Syntax
dim :: QuasiQuoter Source
Expands to a Proxy
with the phantom type being the dimension specified.
Works in types and expressions.
Examples:
id [dim|3 4 5|] ==> id (Proxy :: Proxy (3:.4:.5:.Z))
Proxy :: [dim|3 4 5|] ==> Proxy :: Proxy (3:.4:.5:.Z)
module Data.Proxy