When I first looked at the use of the function keyword in OCaml, I gained the impression that it was syntax sugar to eliminate the match x with line for a pattern match.
However, I see that there is a signature difference between the two as in the example below. In what circumstances would you wish to use the function example?
type e = Foo | Bar
let eval1 exp =
match exp with
| Foo -> "Foo"
| Bar -> "Bar"
let eval2 exp = function
| Foo -> "Foo"
| Bar -> "Bar"
The first function has a signature of val eval1 : e -> bytes = <fun>
The second function has a signature of val eval2 : 'a -> e -> bytes = <fun>