ML-style pattern matching