It's hard to answer without knowing which part is confusing. Here are some simple examples that show some of the trickier parts.
# let f = fun x -> x + 1;;
val f : int -> int = <fun>
# f 3;;
- : int = 4
This defines f
as a function that adds one to an integer. The expression fun args -> expr
defines a function and the let
binds the function to the name f
.
# let f x = x + 1
val f : int -> int = <fun>
# f 3;;
- : int = 4
This defines the same function f. The meaning is exactly the same, it's just a slightly friendlier notation.
For whatever reason, your code is using both of these notations. I'm not sure I see a good reason to do this, but it does emphasize that if you pass three functions to ccc
you'll get a function back.
The other pieces are pretty straightforward (though maybe they take some getting used to):
Function calls are formed just by writing things next to each other:
c1 s1 2
c2 s2 n
c3 s3 n
These are just calls to c1
, c2
, and c3
.
Tuples are formed using commas (and conventionally parentheses also). So (t1, r1)
is a pair of values that is returned by the call to c1
.
I assume you understand if
/ then
/ else
, and let
in
. If not, they aren't hard to explain.
I'd actually suggest reading a tutorial on OCaml. It should be more efficient than asking questions one at a time on SO. There are good tutorials at ocaml.org.