We've seen how rscc is a dialect of ML, and also how to implement pattern matching visitors. In this proposed extension I borrow from the last major syntactic element of ML, the match statement.
switch(ast) { case expr{true}: case expr{false}: // fall-through (like '|' in ML) {...} break; case expr{\a + 5}: case expr{5 + \a}: // fall-through again (see below) {...} break; case expr{\a + 5}: case stmt{\a}: // invalid: should be a shape error (see below) {...} break; default: // no match (as usual) {...} break; }
The switch statement has been overloaded to support pattern matching in the same way as ML's match. As in method patterns for visitors, slots in pattern-matching switches should be locally bound, un-addressable, and opaque.
It should be possible to perform an 'or' match (fall-throughs in the above example) which shares slots on each 'or'ed case. IMO, this is a very useful feature of ML's match which we should attempt to duplicate. The shape checker would be put to the test. I think the types should have to match exactly. So, if the type of \a in one case is a union type of typeclass and expr, it is required to be a union of the same types in all other fall-through cases for that switch. I'm not sure how subtyping should be used (ie., if x <: y, is \a allowed to match x in one case and y in another?).