Safe Haskell | None |
---|---|

Language | Haskell2010 |

Data structures for working with arrays

## Synopsis

- data Nest a
- nest :: Finite a => Data Length -> Data Length -> a -> Nest a
- nestEvery :: Finite a => Data Length -> a -> Nest a
- unnest :: Slicable a => Nest a -> a
- data Dim d
- type Dim1 = Dim ()
- type Dim2 = Dim Dim1
- type Dim3 = Dim Dim2
- type Dim4 = Dim Dim3
- data InnerExtent d where
- NoExt :: InnerExtent ()
- Outer :: InnerExtent (Dim ())
- (:>) :: InnerExtent (Dim d) -> Data Length -> InnerExtent (Dim (Dim d))

- listExtent :: InnerExtent d -> [Data Length]
- type family MultiNest d a where ...
- multiNest :: forall a d. Finite a => InnerExtent (Dim d) -> a -> MultiNest (Dim d) a
- data InnerExtent' d where
- ZE :: InnerExtent' ()
- OE :: InnerExtent' (Dim ())
- SE :: Data Length -> InnerExtent' d -> InnerExtent' (Dim d)

- listExtent' :: InnerExtent' d -> [Data Length]
- tailExtent' :: InnerExtent' (Dim d) -> InnerExtent' d
- convInnerExtent :: InnerExtent d -> InnerExtent' d
- class Finite2 a where
- numRows :: Finite2 a => a -> Data Length
- numCols :: Finite2 a => a -> Data Length

# Documentation

Nested data structure (see explanation of `nest`

)

## Instances

Add a layer of nesting to a linear data structure by virtually chopping it
up into segments. The nesting is virtual in the sense that

is syntactically identical to `unnest`

(`nest`

h w a)`a`

.

In an expression

, it must be the case that
`nest`

l w a`l*w == `

.`length`

a

`multiNest`

may be a more convenient alternative to `nest`

, expecially for
adding several levels of nesting.

A version of `nest`

that only takes the segment length as argument. The
total number of segments is computed by division.

In an expression

, it must be the case that
`nestEvery`

n a`div (`

.`length`

a) n * n == `length`

a

This assumption permits removing the division in many cases when the nested structure is later flattened in some way.

data InnerExtent d where Source #

A description of the inner extent of a rectangular multi-dimensional structure. "Inner extent" means the extent of all but the outermost dimension.

For example, this value

`Outer`

`:>`

10`:>`

20 ::`InnerExtent`

(`Dim`

(`Dim`

(`Dim`

())))

describes a three-dimensional structure where each inner structure has 10 rows and 20 columns.

NoExt :: InnerExtent () | |

Outer :: InnerExtent (Dim ()) | |

(:>) :: InnerExtent (Dim d) -> Data Length -> InnerExtent (Dim (Dim d)) infixl 5 |

listExtent :: InnerExtent d -> [Data Length] Source #

Return the inner extent as a list of lengths

type family MultiNest d a where ... Source #

Add as much nesting to a one-dimensional structure as needed to reach the given dimensionality

multiNest :: forall a d. Finite a => InnerExtent (Dim d) -> a -> MultiNest (Dim d) a Source #

Turn a one-dimensional structure into a multi-dimensional one by adding
nesting as described by the given `InnerExtent`

data InnerExtent' d where Source #

A version of `InnerExtent`

for internal use

ZE :: InnerExtent' () | |

OE :: InnerExtent' (Dim ()) | |

SE :: Data Length -> InnerExtent' d -> InnerExtent' (Dim d) |

listExtent' :: InnerExtent' d -> [Data Length] Source #

tailExtent' :: InnerExtent' (Dim d) -> InnerExtent' d Source #

convInnerExtent :: InnerExtent d -> InnerExtent' d Source #

# 2-dimensional arrays

class Finite2 a where Source #