Re: Re: pattern matching on fields of the argument
Daniel Bonniot <[email protected]> Wed, 11 Aug 2004 11:13:04 +0200
| Newsgroups | gmane.comp.lang.nice.devel |
|---|---|
| Message-ID | <[email protected]> |
>>operator-overloding to use any operator for this meaning, given that
>>type expressions are becoming first-class (in the CVS version
>>fully-qualified types are, and I think I will generalize it to others
>>too).
>
>
> Like Cayenne?
No, it's not a fundamental change in the type system. It's the idea that types
can appear in the syntax anywhere an expression is expected. These type
expressions denote a java.lang.Class at runtime, and they can also be used
with operators that expects a type, like instanceof. So you could write an
operator that does the same thing as instanceof:
<T,U> boolean `/` (T value, Class<U> type) = `instanceof`(value, type);
and use it like:
InputStream x = ...;
if (x/java.io.BufferedInputStream)
{...}
Something that could make it to nice.lang would be a version of cast where you
can specify the target type. It can now be implemented in pure Nice:
<T, U> U cast(T value, Class<U> type) = cast(value);
That's mostly redundant when you assign to a local variable (since you can
declare its type), but is useful when using directly inside a complex
expression. Not sure if we should encourage that or not.
Cheers,
Daniel
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285