A hyperrectangular (or multidimensional) array with a type-level
shape.
>>> array @[2,3,4] @Int [1..24]
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
>>> array [1..24] :: Array '[2,3,4] Int
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
>>> pretty (array @[2,3,4] @Int [1..24])
[[[1,2,3,4],
[5,6,7,8],
[9,10,11,12]],
[[13,14,15,16],
[17,18,19,20],
[21,22,23,24]]]
>>> array [1,2,3] :: Array '[2,2] Int
*** Exception: Shape Mismatch
...
In many situations, the use of
TypeApplication can lead to a
clean coding style.
>>> array @[2,3] @Int [1..6]
[1,2,3,4,5,6]
The main computational entry and exit points are often via
index and
tabulate with arrays indexed by
Fins:
>>> index a (S.UnsafeFins [1,2,3])
23
>>> :t tabulate id :: Array [2,3] (Fins [2,3])
tabulate id :: Array [2,3] (Fins [2,3])
:: Array [2, 3] (Fins [2, 3])
>>> pretty (tabulate id :: Array [2,3] (Fins [2,3]))
[[[0,0],[0,1],[0,2]],
[[1,0],[1,1],[1,2]]]