Navigation
Synopsis Type constrained abstract pattern.
Syntax [Type] Pat
Description A type constrained pattern matches provided that the subject has type Type and Pat matches. This can be handy in case of ambiguity (say more than one constructor with the same name), or in case the pattern is completely general. See an example below:

This does not seem to work properly. There is a bug.
Examples
rascal>import IO;
ok
Some example data type which contains generic values as well as specific expressions:
rascal>data Exp = val(value v) | add(Exp l, Exp r) | sub(Exp l, Exp r);
ok
rascal>ex = add(add(val("hello"(1,2)),val("bye")), sub(val(1),val(2)));
Exp: add(
  add(
    val("hello"(1,2)),
    val("bye")),
  sub(
    val(1),
    val(2)))
Here we constraint the match to find only Exps:
rascal>visit (ex) {
>>>>>>>  case [Exp] str name(_,_) : println("node name is <name>");
>>>>>>>}
node name is hello
node name is add
node name is sub
node name is add
Exp: add(
  add(
    val("hello"(1,2)),
    val("bye")),
  sub(
    val(1),
    val(2)))
Here we do not constrain the same pattern:
rascal>visit (ex) {
>>>>>>>  case str name(_,_) : println("node name is <name>");
>>>>>>>}
node name is hello
node name is add
node name is sub
node name is add
Exp: add(
  add(
    val("hello"(1,2)),
    val("bye")),
  sub(
    val(1),
    val(2)))
[Edit] | [New Subconcept] | [Recompile Course] | [Warnings] 1 warning in this concept
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.