Is it possible to pass a reference to a function to another function in F#? Specifically, I'd like to pass lambda functions like
foo(fun x -> x ** 3)
More specifically, I need to know how I would refer to the passed function in a function that I wrote myself.
Yes, it is possible. The manual has this example:
> List.map (fun x -> x % 2 = 0) [1 .. 5];;
val it : bool list
= [false; true; false; true; false]
Functions are first class citizens in F#. You can therefore pass them around just like you want to.
If you have a function like this:
let myFunction f =
f 1 2 3
and f is function then the return value of myFunction is f applied to 1,2 and 3.
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