next up previous contents index
Next: Refining a datatype Up: Pattern Matching Previous: Repetition

Pattern syntax

The basic form of a pattern is a literal, which that matches only a single integer, real number, string, etc. Complex patterns can be constructed inductively using datatype constructors, tuples, lists, and logical pattern connectives.

The syntax of the patterns is as follows:

Pat ::=Integer matches integer literal
  |  Real matches real literal
  |  Char matches character literal
  |  Quark matches quark literal
  |  String matches string literal
  |  Regexp matches any string that matches regexp
  |  Pat_Var a pattern variable; matches anything
  |  _ wild card; matches anything
  |  Cons matches a datatype constructor
  |  Cons PatArga constructor application pattern
  |  Id as Pat binds a variable to the sub-pattern
  |  Pat : Type_Exp typed pattern
  |  Pat  - - Pat matches either pattern
  |  Pat && Pat matches both patterns
  |  ! Pat matches anything but the pattern
  |  ( Pat ) Grouping
  |  #[ Pat, ¼ , Pat ] list pattern; exact length match
  |  #[ Pat, ¼ , Pat ... ] list pattern; non-exact length match
  |  [ - Pat, ¼ , Pat - ] vector pattern; exact length match
  |  [ - Pat, ¼ , Pat ... - ] vector pattern; matches to the left
  |  [ - ... Pat, ¼ , Pat - ] vector pattern; matches to the right
PatArg ::=Pat 
  |  ( Pat, ¼ , Pat )
  |  { Lab_Pat, ¼ , Lab_Pat [ ... ] }
Lab_Pat ::=Id = Pat 
Pat_Var ::=Id 
  |  ?Id 



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