# repa-sized

Type-safe multi-dimensional array operations in Haskell, wrapping parts of the API of Repa to keep track of each array dimension size (not just number of dimensions) in the type system, preventing some common run-time errors (which become compile-time errors).

# 1 Usage

Most definitions have the same names as Repa, so import qualified if you need both.

Notably different: repa-sized shape uses ZZ ::. 1 ::. 2 ::. 3 (type-level Nat), Repa shape uses Z :. Int :. Int :. Int, runtime indices use Z :. 0 :. 1 :. 2.

This is because qualified imports would make it painful when using both in the same source code file (as may be common).

# 2 Safety

The WithShape constructor is exported. If you use it carelessly you can fake any array dimensions you like, breaking everything. But it is necessary for wrapping third party libraries that extend Repa…

Some runtime indices (e.g. in backpermute) are not statically checked for safety, so runtime errors are still possible if you make a mistake.

# 3 Convenience

Some operations (e.g. select, reading image files from disk, …) can produce differently sized arrays depending on data that is not known at compile time. This is handled in repa-sized via the RankNTypes extension, which is not very convenient to use.

Some error messages are bad (e.g. “can’t match False with True” in extract means the region extends outside the bounds of the array).

# 4 Extras

Some small features not found in Repa. Subject to change (e.g. removal to a different library).

# 4.1 bop

bop is like zipWith, but it repeats (cycles in each dimension) the right hand argument to match the dimensions of the left hand argument, which is also the dimensions of the output.

The dimensionality of the right hand side may be less than the left hand side, earlier dimensions are assumed to be 1 and are cycled also.

Contrast to zipWith which intersects the dimensions with min.

Inspired by GridFlow’s [#] object.

# 4.2 nest

Turn an array into an array of arrays.

# 4.3 denest

Turn an array of arrays into an array.

# 5 Source

Browse: code.mathr.co.uk/repa-sized.

git clone https://code.mathr.co.uk/repa-sized.git

Or, soon (not yet published to Hackage), add

repa-sized >= 1 && < 1.1,

to the build depends in your .cabal file and run cabal update && cabal repl or similar.