Chapel: Determine eltType from "most general type" for all array elements

Created on 15 Jan 2018  路  4Comments  路  Source: chapel-lang/chapel

It appears I have to take all my integers in an array and put either a .0 or at least . after the number. For instance

var d = Matrix([3.0 , 7, 4.3], [4.7 , 9, 22.8]);
> pginsert.chpl:29: error: Array literal element 2 expected to be of type real(64) but is of type int(64)

I think Chapel arrays assume reals, so why not just take that 7 at 7.0?

Language Feature Request user issue

Most helpful comment

I think Chapel arrays assume reals

To help prevent the spread of misinformation: this statement isn't accurate鈥擟hapel arrays can be of any type and no assumption is made about what the type is when looking at an array literal.

That said, the request is completely reasonable and appropriate. I'd describe it as: Try to find a unified "most general type" for all array elements, similar to how we do so for return statements that return different types:

config var flag = true;

proc foo() {
  if flag then
    return 1;
  else
    return 2.3;
}

var a = foo();
writeln(a.type:string);

All 4 comments

An even more distilled example of this:

var A = [1, 2.0];
> chpl a.chpl
a.chpl:1: error: Array literal element 2 expected to be of type int(64) but is of type real(64)

it's like your shooting for the "everclear of array examples". Gotta have goals in life.

I think Chapel arrays assume reals

To help prevent the spread of misinformation: this statement isn't accurate鈥擟hapel arrays can be of any type and no assumption is made about what the type is when looking at an array literal.

That said, the request is completely reasonable and appropriate. I'd describe it as: Try to find a unified "most general type" for all array elements, similar to how we do so for return statements that return different types:

config var flag = true;

proc foo() {
  if flag then
    return 1;
  else
    return 2.3;
}

var a = foo();
writeln(a.type:string);

I believe what @buddha314 meant was that LinearAlgebra.Matrix() assumes eltType=real when no eltType argument is specified.

Was this page helpful?
0 / 5 - 0 ratings