Richard Gomes <[email protected]> wrote on 11/11/2010 10:52:05 PM:
> Hi guys,
>
> I was wondering if it would be possible to assign annotations to types
> and employ an annotation processor in order to detect the situation
> below which tries to detect if parametres were passed in wrong order.
>
>
> public class Hello {
>
> static type Left = Double;
> static type Right = Double;
>
> public static def main(Array[String]) {
>
> val left : Left = 2.2;
> val right : Right = 2.5;
>
> val o = new Hello();
>
> val pass = o.f(left, right); // compiles OK
>
> val fail = o.f(right, left); // should not compile !!!!!
>
> }
>
> def f(l : Left, r : Right) : Double = { ... }
>
> }
Hi, Richard,
Well, typedefs in X10 are real aliases, and don't define new types,
so the above will not work as written. However, annotations on
types like those proposed in JSR-308 are permitted in X10, so one
can write:
val left : Double @Left = 2.2;
val right : Double @Right = 2.5;
...
val pass = o.f(left, right);
val fail = o.f(right, left);
...
def f(l: Double @Left, r: Double @Right) : Double = ...;
and create a checker that would ensure that the second invocation
fails to compile. One could also write a compiler plugin to
generate code on casts, so that the following would perform the
necessary conversions, if any:
val right : Double @Right = (left + .3) as Double @Right;
Let us know if you're interested in this functionality, and we
can expand on this.
Igor
--
Igor Peshansky (note the spelling change!)
IBM T.J. Watson Research Center
X10: Parallel Productivity and Performance (http://x10-lang.org/)
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
"I hear and I forget. I see and I remember. I do and I understand" --
Xun Zi
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users