在 Haskell 中,我如何 return 具有递归定义的柯里化函数?

In Haskell, how would I return a curried function that has a recursive definition?

我试图在 Haskell 中实现以下(在 Javascript 中定义): JS:

const fold = (c, h) => {
  const f = (n) => {
    return n === 0 ? c : h (f(n-1))
  }
  return f
}

fold(1, (x)=>x*10)(3)

回复Link:https://repl.it/repls/ExperiencedTeemingLorikeet

我尝试了这些方法(但不起作用):

foldn c h =
 f  = f' n
      where f' 0 = c
            f' n =  h(f'(n-1))
 f

本质上,我正在尝试创建一个可以返回的命名柯里化函数 "f"。还要注意 "f" 的定义是 recursive 我如何在 Haskell 中执行此操作?

实际上,Haskell中的所有函数默认都是柯里化的,所以你可以这样做

fold c h n = if n == 0 then c else h (fold c h (n-1))

如果你还是喜欢里面有一个f,那么

fold c h = f
    where
        f 0 = c
        f n = h (f (n-1))

这些版本是等价的,可以这样调用

fold 1 (*10) 3

你很接近。只需声明一个关闭 ch.

的函数
foldn c h = f where
  f 0 = c
  f n =  h . f $ n-1