Add an example of a pattern guard.

Sometimes, syntactic pattern matching is not precise enough. For
instance, say you are given the task of formulating a simplification
rule that replaces sum expressions with two identical operands such as e
+ e by multiplications of two, e.g., e * 2. In the language of Expr
trees, an expression like:

BinaryOperator("+", Var("x"), Var("x"))

would be transformed by this rule to:

BinaryOperator("*", Var("x"), Number(2))

You might try to define this rule as follows:

def simplifyAdd(e: Expr) = e match {
  case BinaryOperator("+", x, x) => BinaryOperator("*", x, Number(2))
  case _ => e
}
<console>:11: error: x is already defined as value x
         case BinaryOperator("+", x, x) => BinaryOperator("*", x, Number(2))
                                     ˆ
This fails, because Scala restricts patterns to be linear: a pattern
variable may only appear once in a pattern. However, you can
reformulate the match with a pattern guard, as shown in this commit.

A pattern guard comes after a pattern and starts with an if. The guard
can be an arbitrary boolean expression, which typically refers to
variables in the pattern. If a pattern guard is present, the match
succeeds only if the guard evaluates to true. Hence, the first case
above would only match binary operations with two equal operands.