chapel icon indicating copy to clipboard operation
chapel copied to clipboard

Feature Request: Extracting domain and type on variable assignment

Open Iainmon opened this issue 2 years ago • 1 comments

It is very nice to bind the domain and type of a value that is not explicitly known:

proc makeArr() {
    return [1,2,3,4,5];
}

proc runSomething(a: [?d] ?t) {
    writeln(a, d, t:string);
}

runSomething(makeArr());

It would be convinient if the following syntax could be supported

var a: [?d] ?t = makeArr(); 

It could also just be treated as a shorthand for

var a = makeArr();
var d = a.domain;
type t = a.type;

This would also apply to situations where the element type is known, but the domain may vary.

var a: [?d] real = makeArr();

Iainmon avatar Jul 07 '23 16:07 Iainmon

This request is somewhat related to https://github.com/chapel-lang/chapel/issues/10596 and also feels compatible with recent improvements to support increasingly generic type expressions for variable declarations, with the initializing expression filling in the missing details.

bradcray avatar Jul 07 '23 17:07 bradcray