I am trying to achieve the following (defined in Javascript) in Haskell: JS:
const fold = (c, h) => {
const f = (n) => {
return n === 0 ? c : h (f(n-1))
}
return f
}
fold(1, (x)=>x*10)(3)
Repl Link: https://repl.it/repls/ExperiencedTeemingLorikeet
I tried something along these lines (but does not work):
foldn c h =
f = f' n
where f' 0 = c
f' n = h(f'(n-1))
f
Essentially I am trying to create a named curried function "f" that can be returned. Also note that the definition of "f" is recursive How can I do this in Haskell?