The F# developer can use pattern matching syntax pretty much anywhere in F#. For example, consider the following list:
let l = [1..25]
If I want to get the last element of the list, I can do this with a little trivial pattern match:
let lastElem::_ = l |> List.rev;; stdin(7,5): warning FS0025: Incomplete pattern matches on this expression. For example, the value '' may indicate a case not covered by the pattern(s). val lastElem : int = 25
In this case, you can safely ignore the warning.
You can also pull one of the elements from a tuple very easily with this pattern match:
let name,_ = (“Onorio”,”11W”);; val name : string = "Onorio"
The underscore character in both of these pattern matches functions as a wildcard. In both cases it signifies a value that we don’t care about.
There’s also a (pretty dated) question at StackOverflow that covers this very issue:
Pingback: F# Weekly #33 2013 | Sergey Tihon's Blog