See the docs on pattern matching syntax. function
is a shorthand syntax for taking a single argument and immediately pattern matching:
let foo x =
match x with
| CaseA -> 1
| CaseB -> 2
Is the equivalent of
let foo = function
| CaseA -> 1
| CaseB -> 2
Note that function
just adds one argument, it doesn't enforce that there is exactly one argument. For example, this is acceptable:
let foo x y = function
| CaseA -> x + y
| CaseB -> x - y
And is equivalent to
let foo x y z =
match z with
| CaseA -> x + y
| CaseB -> x - y
Edit:
(For completeness) And as for [l]
, like Lee said, that's just a match pattern. Specifically, a structural match pattern on lists which matches lists with a single element, and binds that element to the identifier l
. See "List Pattern" here.