Nick,
To add to Mike's response, we discussed generic classes very recently. Here are
our current thoughts.
(A) For the initial implementation, continue treating type fields and arguments
the way they are treated today. In brief, an initializer specifies the type for
a type field via a formal argument named the same as the field. For example:
class C {
type MyType;
...
proc init(type MyType, ...) { ... }
}
new C(real, ...); // instantiate C with MyType = real
MyType formal does not have to be ordered according to the field order. It can
be left out only if MyType field specifies a default value, e.g. "type MyType =
int;".
(B) In the long run, we are considering uniform treatment of generic and
non-generic fields. That is, an initializer specifies the type for a type field
by setting it explicitly during Phase 1.
The following initializer shows that such a type does not have to come from a
formal argument (it can if desired):
class C {
type MyType;
...
proc init(...) { MyType = real; super.init(); ... }
}
new C(...); // instantiate C with MyType = real
// provided the above initializer is invoked
(A) and (B) apply to the other generic fields as well, i.e. var/const fields
whose type and default value are not specified in the field declaration, and
param fields.
BTW we have an interesting puzzle. Consider this simplified example from
BlockDist, written under (A).
class BlockDist {
param rank: int;
var boundingBox: domain(rank);
}
proc BlockDist.init(boundingBox, param rank = boundingBox.rank) { }
test(BlockDist(rank=1)); // 1-dimensional
proc test(type T) {
const boundingBox = {1..1,2..2}; // 2-dimensional
new T(boundingBox);
}
The call "new T" will try to invoke the initializer on a 1-D BlockDist, passing
a 2-D bounding box as an argument. This should be a compile-time error.
The puzzle is: what are the rules that specify this behavior? Ditto for (B)?
Vass
On 05/04/16 18:10, Nicholas Park wrote:
> I didn't see any discussion of initializers for type-generic classes (i.e.,
> classes with "type" fields). Currently, these type arguments are handled
> differently than regular arguments in constructors. How does the team
> expect initializers to handle generic types and type arguments?
>
> Nick
>
> ...
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users