I have an OCaml function which I got from the post: List reversing in Ocaml
let rev_list l =
let rec rev_acc acc = function
| [] -> acc
| hd::tl -> rev_acc (hd::acc) tl
in
rev_acc [] l
I tested this, and it obviously worked, but I don't understand why. Inside the main function, when defining rev_acc
, it says that it only takes on argument acc
. However, when then call the function with two parameters. Why are we allowed to do this?
Also, why do we say let rec rev_acc acc = function
, what does the "= function" mean, and why aren't we using a match? I'm assuming this has to do with not having to specify certain arguments; I do remember something about that in the last part of the course, which was only briefly covered. Does it have anything to do with currying?
Sorry if these are stupid questions; I'm rather new to functional programming, if that wasn't already obvious.
Any help is greatly appreciated. Thanks.