Hello Chapel developers,

I was using generic classes recently and I ran into a few issues. My
preemptive apologies if this is a "read the manual" issue that I missed.

*Issue #1: Type methods on generic classes are unintuitive*
I was building a generic class and wanted a type method on it. Here's a
simplified and contrived example:

> class Foo {
>   type eltType;
>   var data: eltType;
> }
>
> proc type Foo.build(type eltType, N: eltType) {
>   var temp = * reduce {1..N};
>   return new Foo(eltType, temp);
> }
>
> var foo = Foo(int).build(int, 4)
> writeln(foo);
> delete foo;
>

To me, the unintuitive part is that calling the type method requires a
fully-specified type instance of Foo. Here Foo(int) works, but so does
Foo(real) and Foo(string), which is further unintuitive because foo.data is
still an int.

Ideally (to me), the method signature and call would look something like:

> proc type Foo(?eltType).build(N: eltType) { ... }
>
var foo = Foo(int).build(4);
>
but this is not currently valid and, AFAICT, I can't get the eltType info
from the type on which build() was called.


*Issue #2: Class inheritance of generic classes seems broken (or really
unintuitive)*
Here's more simplified and contrived code (which doesn't compile):

> class Bar {
>   type eltType;
>   var barData: eltType;
> }
>
> class Baz : Bar {
>   var bazData: eltType
> }
>
> var baz = new Baz(int);
>
writeln(baz);
>
delete baz;
>

Ideally, Baz is a generic class that can know about Bar's eltType and use
it, however, I cannot figure out how to get this type information out of
Bar. I've tried a few other variations, including making Baz generic on its
own type, but I either end up with constructor mismatches or issues on the
"class Baz : Bar" line.

Thanks,

Nick
------------------------------------------------------------------------------
Presto, an open source distributed SQL query engine for big data, initially
developed by Facebook, enables you to easily query your data on Hadoop in a 
more interactive manner. Teradata is also now providing full enterprise
support for Presto. Download a free open source copy now.
http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to