[e-lang] Generators for the other Joe-E array types

David Wagner daw at cs.berkeley.edu
Sun Dec 16 00:30:02 EST 2007

Tyler Close writes:
>I think we need generators, like the recently discussed
>ByteArray.Generator class, for all the other Joe-E array types as

This sounds good to me.  Adrian, what do you think?  Are you okay
with this?

>I think we need something like:
>    interface Generator<T> {
>        void append(T value);
>        ConstArray<T> snapshot();
>    }

You mentioned that you wanted to eliminate all unsafe casts.  The
interface above may require casting the return value of snapshot()
to the appropriate subtype of ConstArray.  For example, consider the
following usage:
    Generator<T> g = PowerlessArray.generate(n);
    PowerlessArray<T> a = (PowerlessArray<T>) g.snapshot();
The last line requires an unchecked cast.  Is that okay?  Would you
prefer to have the interface be designed to be statically type-safe?

For example, would the following alternative be better?
    interface Generator<A extends ConstArray<T>,T> {
        void append(T value);
        A snapshot();
Each Joe-E array type would provide a generate() method that returns
the appropriate type; e.g., PowerlessArray<T>.generate()'s return type
would be Generator<PowerlessArray<T>,T>.  That would eliminate the
need to cast the return value of Generator.snapshot() to the appropriate
array type.  Does this seem like an improvement?

More information about the e-lang mailing list