osdir.com
mailing list archive

Subject: Re: Generators for the other Joe-E array types - msg#00012

List: lang.e.general

Date: Prev Next Index Thread: Prev Next Index
Hi David,

On Dec 15, 2007 9:30 PM, David Wagner
<daw-Sd3DkRwxp1uueSrTVlFI5A@xxxxxxxxxxxxxxxx> wrote:
> 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?

I was thinking PowerlessArray would provide a public implementation of
the Generator interface and make use of Java's support for covariant
return types in the implementation of the snapshot() method, so...

public final class
Generator<T> implements org.joe_e.array.Generator<T> {

...
public PowerlessArray<T>
snapshot() { return ...; }
}

Use would then be:

PowerlessArray.Generator<T> g = PowerlessArray.generate(n);

PowerlessArray<T> a = g.snapshot();

This is similar to how the ByteArray.Generator class currently works.

--Tyler

--
The web-calculus is the union of REST and capability-based security:
http://www.waterken.com/dev/Web/

Name your trusted sites to distinguish them from phishing sites.
https://addons.mozilla.org/firefox/957/


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Generators for the other Joe-E array types

Tyler Close writes: >I think we need generators, like the recently discussed >ByteArray.Generator class, for all the other Joe-E array types as >well. 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?

Next Message by Date: click to view message preview

Generators for the other Joe-E array types

Tyler Close writes: >I was thinking PowerlessArray would provide a public implementation of >the Generator interface and make use of Java's support for covariant >return types in the implementation of the snapshot() method, so... > > public final class > Generator<T> implements org.joe_e.array.Generator<T> { > public PowerlessArray<T> > snapshot() { return ...; } > } Got it. That should do the trick nicely.

Previous Message by Thread: click to view message preview

Generators for the other Joe-E array types

Tyler Close writes: >I think we need generators, like the recently discussed >ByteArray.Generator class, for all the other Joe-E array types as >well. 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?

Next Message by Thread: click to view message preview

Re: Generators for the other Joe-E array types

This all looks good so far; I'll put out a version of the library that includes this after Christmas, along with the runtime taming stuff. The new version of the verifier that includes this is making progress and should be released in early January (it won't quite be ready before the holidays). -Adrian David Wagner wrote: > Tyler Close writes: >> I think we need generators, like the recently discussed >> ByteArray.Generator class, for all the other Joe-E array types as >> well. > > 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? > _______________________________________________ > e-lang mailing list > e-lang-r2jiIPW7MOYEUp5O9OQuKg@xxxxxxxxxxxxxxxx > http://www.eros-os.org/mailman/listinfo/e-lang
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by