When literals are used in pattern matching there is no check that the subsequent expression/pattern argument list is empty, e.g.
module Color =
let [<Literal>] Yellow = "Yellow"
let isRed inp =
match inp with
| Color.Yellow arg -> // should get an error here
failwith "Don't know this color"
nor that the right arrow in the pattern match is not missing, e.g.
let isRed = function
| Color.Red ->
true
| Color.Yellow /// Notice the missing -> here
you can insert what you want here like booleans false "strings" _and numbers 42. Yes it still compiles
| _ ->
failwith "Don't know this color"
As a side effect the match on Color.Yellow never holds.
For reference when using discriminated unions instead of literals you get the expected behavior:
module Color =
type Y = | Yellow | Green
let isRed inp =
match inp with
| Color.Yellow arg -> // we do get an error here
failwith "Don't know this color"
When literals are used in pattern matching there is no check that the subsequent expression/pattern argument list is empty, e.g.
nor that the right arrow in the pattern match is not missing, e.g.
As a side effect the match on Color.Yellow never holds.
For reference when using discriminated unions instead of literals you get the expected behavior: