Array parameters of generic types

One can say

proc max(x : real(?w), y : real(w))

and

proc multiplyMatrixA(z : [?zD] ?R, x : [?xD] R, y : [?yD] R)

but not

proc multiplyMatrixA(z : [?zD] real(?w), x : [?xD] R, real(w) : [?yD] real(w))

Have I lost the plot totally or is that just the way things are?

The current compiler handles real(?w) formal arguments in a special way and that's not currently working when combined with an array (like z: [?zD] real(?w)).

proc test(z : [?zD] real(?w)) {
  writeln("in test, z=", z);
}

var A: [1..10] real;

test(A);
chpl bb.chpl
bb.chpl:1: In function 'test':
bb.chpl:1: error: Query expressions are not currently supported in this context
  bb.chpl:1: called as test(z: [domain(1,int(64),false)] real(64))
note: generic instantiations are underlined in the above callstack

This is something that we would like to improve upon with the new resolver along with adjustments to how int(?w) etc are handled (and we have been discussing related language design points in instantiation+implicit conversion for numeric types · Issue #20011 · chapel-lang/chapel · GitHub ). With those efforts, I would expect we could get the above case (as well as your 3rd example) to work.

For now, a workaround is to use a where clause:

proc add(x : [], y : [])
  where isRealType(x.eltType) && isRealType(y.eltType) &&
  numBits(x.eltType) == numBits(y.eltType) {
  param width = numBits(x.eltType);
  writeln("in add, x=", x, " y=", y, " width=", width);
}

var A: [1..2] real(32);

add(A, A);

Here is a version using more of a type query style (so more similar to your original):

proc add(x : [?xD] ?elt, y : [?yD] elt) where isRealType(elt) {
  param width = numBits(x.eltType);
  writeln("in add, x=", x, " y=", y, " width=", width);
}

var A: [1..2] real(32);

add(A, A);

Hope that helps.

It does. Thanks.