定数値の代わりに変数でパターンマッチングを行うことは可能ですか?
# 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"
明らかに、この構文では、x -> "foo"
ケースがすべてを取ります。それを以下と同等にする方法はありますか?
match 2 with
| 2 -> "foo"
| 5 -> "bar"
| _ -> "baz"
一致式の値は実行時に決定されますか?