Considering the following code example:
import lang::nl::Parser;
registerLanguage("Dutch", "nl", Dutch(str input, loc origin) {
return parse(input, origin);
});
I wondered, if I could rewrite it as:
registerLanguage("Dutch", "nl", lang::nl::Parser::parse);
Then Rascal gives me:
The called signature: registerLanguage(str, str, value),
does not match the declared signature: registerLanguage(str, str, Tree (str, loc))
While the return type of parse() is Dutch. Is it possible to pass a function as a parameter to registerLanguage? Do I need to hint Rascal about the type?
You are getting value because of the way the type system is treating the two parse functions you have in lang::nl::Parser -- since they have different signatures (including different numbers of parameters) the most general type that includes both functions is value, which is why value is in the called signature. To work around this, you can either change the name or introduce another function that calls your existing parse function. We don't have a method right now to specific which of the overloads to use in such situations (which would also be a solution if we had it).
Asked: Jan 23
Seen: 11 times
Last updated: Jan 23
Copyright CWI, 2010-2012. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
Could you also post the code in lang::nl::Parser, especially the parse function? Also, do you have multiple parse functions declared in that module?
MarkHills (Jan 23)editpublic Dutch parse(str input) = parse(#Dutch, input); public Dutch parse(str input, loc origin) = parse(#Dutch, input, origin);
Arjen (Jan 23)edit