I have encountered alias sign inside RGL in this operation:
mkRoot3 : Str -> Root3 = \fcl -> case fcl of {
f@? + c@? + l => {f = f ; c = c ; l = l} ;
_ => error ("mkRoot3: too short root" ++ fcl)
} ;
What does it mean, and what's the use of it?
The character @ is used in pattern matching. The expression
foo@barmeans that you match something with the regexbar, and bind the result to variablefoo.Let's first recap some ways you can pattern match a string without @:
In all of these, we are not reusing the string in the right-hand side. If you want to do that, you can just bind it into a variable, like this—not yet using @ , because we are simply matching the start and the end of a string:
Finally, if you want to match something to a regular expression and use whatever matches the regex on the RHS, now you need to use @:
If you just tried to match
a + b => …, or any other pattern that only contains variables, it wouldn't match words that are exactly 2 characters long. Instead it would just match empty string to one of them and the full string to the other.So matching the regex
?, which matches exactly one character, and then binding the result to a variable, is the only way you can match something with exact length, and then reuse the matched character/string on the right-hand side.You can read more on pattern matching at http://www.grammaticalframework.org/doc/gf-refman.html#pattern-matching .