在为高阶函数传递函数时调用递归函数

calling recursive function when passing a functon for higher order function

我想递归调用高阶函数。所以我有一个列表,我将把这个列表传递给函数名 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