docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

#E0142: rows of an array literal differ in length

A nested list literal in an Array<T, N> slot builds an array of rank N: every row at one depth must have the same length, since the result is a rectangle ([[1, 2], [3, 4]] is 2 x 2). Make the rows the same length, keep a ragged structure as a List<List<T>>, or give the slot the rank the nesting has.

nabi
use core::array::Array;

let m: Array<f64, 2> = [[1.0, 2.0], [3.0, 4.0, 5.0]];
error[E0142]: this row has 3 elements, the first row at its depth has 2
  --> main.nabi:3:37
   |
 3 | let m: Array<f64, 2> = [[1.0, 2.0], [3.0, 4.0, 5.0]];
   |                                     ^^^^^^^^^^^^^^^
   |
   = help: give every row the same length, or keep ragged rows in a `List<List<T>>`

Give every row the same length, or keep the rows in a list of lists:

nabi
use core::array::Array;

let m: Array<f64, 2> = [[1.0, 2.0], [3.0, 4.0]];
let rows: List<List<f64>> = [[1.0, 2.0], [3.0, 4.0, 5.0]];
println(f"{m.shape():?} {rows[1].len()}");
[2, 2] 3

Related: E0040 mismatched types

Found a mistake? Edit this page on GitHub. Last updated