问题描述
我想递归调用高阶函数。所以我有一个列表,并将此列表传递给函数名称funcName。但是我需要传递一个函数。我想在这里讲逻辑。我想检查元素是否为eric。如何为有趣的i->语法提供递归函数?
let aaa c : bool =
let rec helper c =
match c with
|element(i) -> funcName (fun i->if (List.hd i)=eric then true else
//Now i want to recursively call List.tl inside this inner function
in
helper c
解决方法
您似乎在询问如何将定义为fun
(无名)的函数递归调用。
有很多方法可以做到这一点,但是(我认为)它们比值得的更为复杂。
您可以为无名函数命名:
let aaa c : bool =
let rec helper c =
let rec helper_helper i =
if List.hd i = eric then true
else (* Do your recursive calling of helper_helper *)
in
match c with
| Element i -> funcName helper_helper
in
helper c