Ask Your Question
0

Type inference of functions in parameters

asked Jan 23

Arjen gravatar image Arjen
13 2 4

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?

delete close flag offensive retag edit

Comments

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)edit

public Dutch parse(str input) = parse(#Dutch, input); public Dutch parse(str input, loc origin) = parse(#Dutch, input, origin);

Arjen (Jan 23)edit

1 Answer

Sort by ยป oldest newest most voted
0

answered Jan 23

MarkHills gravatar image MarkHills
351 6 10

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).

link delete flag offensive edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]
Also see the Rascal Tutor.

Question tools

Follow

subscribe to rss feed

Stats

Asked: Jan 23

Seen: 11 times

Last updated: Jan 23