2
我想申请存储在列表执行的功能
let functions = [(fun() -> print_string "fun 1"); (fun() -> print_string "fun 2")]
与像List.iter高阶功能的功能列表,显示出“乐趣1”和“2乐趣”
有没有办法做到这一点?
我想申请存储在列表执行的功能
let functions = [(fun() -> print_string "fun 1"); (fun() -> print_string "fun 2")]
与像List.iter高阶功能的功能列表,显示出“乐趣1”和“2乐趣”
有没有办法做到这一点?
下面是做到这一点的方式:
List.iter (fun f -> f()) functions
你的清单包括与签名unit -> unit
功能。因此,如果您为每个功能提供()
作为参数,则它们将返回unit
,这在List.iter
内部显而易见。
一个等效的版本,使用'BatPervasives':'List.iter((|>)())函数' – 2012-01-30 00:54:36
没错,但我更喜欢有意义的版本来点一个:)。 – pad 2012-01-30 07:00:37