asked
Dec 19 '11
Johanneke 77 ● 4 ● 10 In the console I can assign the empty set to a variable, without specifying the type of the variable. The type is then set[void]. However, I can still add values of different types to the set, such as a tuple[int,str]. The type of the variable changes to rel[int,str] after this.
rascal>d = {};
set[void]: {}
rascal>d = d + <1,"a">;
rel[int, str]: {<1,"a">}
rascal>d;
rel[int, str]: {<1,"a">}
After this, I would expect the following code to work:
data TestADT = testADT(rel[int,str]);
public void f(testADT(r)) {
r = r + <2,"b">;
}
However, when I try to run this using "f(testADT({}))", I get the message "Expected set[void], but got rel[int, str]". I would expect the pattern matching on testADT to make r of the type rel[int,str], but apparently this doesn't happen?
What is going on? And what can I do to be able to add values of type tuple[int,str] to r?