Is it possible to do pattern matching on variables instead of constant values:
# let x = 2 in
let y = 5 in
match 2 with
| x -> "foo"
| y -> "bar"
| _ -> "baz";;
let y = 5 in
Warning 26: unused variable y.
let x = 2 in
Warning 26: unused variable x.
| y -> "bar"
Warning 11: this match case is unused.
| _ -> "baz";;
Warning 11: this match case is unused.
- : string = "foo"
Obviously, with this syntax, the x -> "foo"
case takes everything. Is there a way to make it be equivalent to:
match 2 with
| 2 -> "foo"
| 5 -> "bar"
| _ -> "baz"
where the values of the match expressions are determined at runtime?