Collection Type Specification [message #1282474] |
Wed, 02 April 2014 11:05 |
Philip Makedonski Messages: 10 Registered: May 2013 |
Junior Member |
|
|
Hi,
I've been trying to grasp whether and to what extent collection types are supported in EOL/ETL. Consider the following example:
var a = new Set(String); //desired
var b = new Set(String); //intentionally "wrong", shall be Set(Integer)
var c = new Set(String); //intentionally "wrong", shall be Set(Real)
var d = new Set;
a.addValue("S");
a.addValue("P");
b.addValue(1);
b.addValue(2);
c.addValue(1.0);
c.addValue(2.0);
d.addValue(a);
d.addValue(b);
d.addValue(c);
(a).println();
(b).println();
(c).println();
(d).println();
operation Set(String) addValue(p : String) {
(p + " (string)").println();
self.add(p);
}
operation Set(String) addValue(p : Integer) { //intentionally "wrong", the context should be Set(Integer)
(p + " (integer)").println();
self.add(p);
}
operation Any addValue(p : Real) {
(p + " (real)").println();
self.add(p);
}
operation Any addValue(p : Collection(Real)) {
(p + " (collection(real))").println();
self.add(p);
}
operation Any addValue(p : Collection(String)) {
(p + " (collection(string))").println();
self.add(p);
}
operation Any addValue(p : Collection(Integer)) {
(p + " (collection(integer))").println();
self.add(p);
}
There doesn't seem to be any difference what type is specified in the Set definition. In addition, while parameter overloading for addValue() works for primitive types in the example above, it doesn't seem to work for typed collections - i.e. executing the above shows that addValue(p : Collection(Real)) is always executed, regardless of what the type and contents of the collection supplied as parameter (or of the context for that matter).
In the example above, it is not really an issue, but in the actual usage scenario the operation bodies vary for the different types of collections.
Thus, my question is: Is there a way to get this to work with parameter overloading in the example above? Or shall I resort to a different solution (different operation names, additional parameter indicating the type, or changing the meta-model).
Thanks in advance!
Cheers,
Philip
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02178 seconds