**Announcement: We are hiring a PhD student to do research on functional high performance computing, including work on Futhark itself. See here for more details.**

# Arrays

Futhark arrays are written as values enclosed in square brackets.

The type of `arr`

is `[]i32`

(or `[3]i32`

to be pedantic). The element type of an array can be another array:

The type of `marr`

is `[][]i32`

. Arrays must be *regular*, meaning that all elements must have the same shape. An array such as `[[1,2], [3]`

is illegal.

Arrays can be indexed from zero:

And sliced:

We can even slice or index only some dimensions:

This produces `[[2], [5]]`

. Slices are inclusive in the starting position and exclusive in the ending position as Dijkstra wills it.

Strides are also supported. Generally, The expression `a[i:j:s]`

returns a slice of the array `a`

from index `i`

(inclusive) to `j`

(exclusive) with a stride of `s`

. If the stride is positive, then `i <= j`

must hold, and if the stride is negative, then `j <= i`

must hold. For example, we can reverse an array like this:

Some syntactic sugar is provided for concisely specifying arrays of intervals of integers. The expression `x...y`

produces an array of the integers from `x`

to `y`

, both inclusive. The upper bound can be made exclusive by writing `x..<y`

. For example:

It is usually necessary to enclose a range expression in parentheses, because they bind very loosely. A stride can be provided by writing `x..y...z`

, with the interpretation “first `x`

, then `y`

, up to `z`

”. For example:

Now `strided`

contains `[1, 3, 5, 7]`

.

## See also

Reference manual: slicing.