Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 527

OCaml higher order functions

$
0
0

Somebody please explain the algorithm in this problem for OCaml.

I have the solution but I do not understand it.

Define iterup: (int * 𝛼→𝛼) → int → int →𝛼→𝛼. Iterup takes a function which receives the current number and the accumulator. It increments the counter number from a given start to a given end and applies the function each time. The last argument is the start value of the accumulator.

The solution is

let rec iterup f st ed acc =   if st > ed then     acc   else     iterup f (st+1) ed (f st acc)

What I do not understand is why we take in both n and s as arguments to f in the last part (f n s). What does that get us to when we talk in terms of tail recursion.


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>