next up previous contents index
Next: Pattern syntax Up: Pattern Matching Previous: Match all rules

Repetition

In addition, both match and matchall can be annotated with the while  modifier. It this case the semantics of the matching construct is to repeat until no more rule is applicable. For example, the following code fragment returns the last element of a list

datatype List = #[] | #[ int ... List ];

int last (List l)
{  match while (l)
   { case #[]:         assert(0); // an error
     case #[i]:        return i;
     case #[h ... t]:  l = t;
   }
}



Allen Leung
Mon Apr 7 14:33:55 EDT 1997