The general form of a Mythryl pattern match statement is
my pattern = expression;
The possibilities here are essentially unchanged from SML:
Mythryl Code | Comment |
my x = 12; | Bind a variable to value. |
x = 12; | “my” may be dropped when pattern is a lone identifier. |
my (x, y) = (12, 13); | Pattern-matching against a tuple. |
my (x, _) = (12, 13); | Partial matching of a tuple. |
my (_, x, _) = (12, 13, 14); | Fancier version of same. |
my { x => x, y => y } = {x => 12, y => 13}; | Pattern-matching against a record. |
my { x, y } = {x => 12, y => 13}; | Convenient abbreviation for previous case. |
my { x, y } = {x, y}; | Same abbreviation may be used when constructing record. |
my { x, ... } = {x => 12, y => 13}; | Partial pattern-matching against a record. |
my r as { x, ... } = {x => 12, y => 13}; | As above, but r matches complete record. |
my (x ! xs) = [ 12, 13 ]; | Match against a list. |