Reputation: 6175
I'd like to apply a functions stored in a list
let functions = [(fun () -> print_string "fun 1"); (fun () -> print_string "fun 2")]
with a high-order function like List.iter, to display "fun 1" and "fun 2"
Is there a way to do that ?
Upvotes: 2
Views: 102
Reputation: 41290
Here is the way to do it:
List.iter (fun f -> f()) functions
Your list consists of functions with the signature unit -> unit
. Therefore, if you supply ()
as a parameter for each function, they will return unit
which is obvious to use inside List.iter
.
Upvotes: 5