Possible Duplicate:
F# explicit match vs function syntax
Hello,
I am learning F# and am confused by 'fun' and 'function' keywords. My understanding is that these are sort of the same thing.
// Use 'fun'
let testFunction1 = fun argument -> match argument with
| Some(x) -> x
| None -> 0
// Use 'function'
let testFunction2 = function
| Some(x) -> x
| None -> 0
Is 'function' just shorthand for "fun x -> match x with"? Is there any runtime / optimization difference between the two? Why would I prefer to use one over the other?
As it stands, 'function' just seems to make code harder to read. Am I missing something?
function only allows for one argument but allows for pattern matching, while fun is the more general and flexible way to define a function. Take a look here: http://caml.inria.fr/pub/docs/manual-ocaml/expr.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With