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

时间:2020-10-04 07:56:06

标签: ocaml higher-order-functions

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

1 个答案:

答案 0 :(得分:1)

您似乎在询问如何将定义为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
相关问题