Decrypting return of function in OCaml

power_output

I'am trying to decrypt the return of calc function below but i'am very confused. I have the f function that takes 3 ints and returns an int. The calc fuction i think should return val calc : int -> int = <fun> because f has to take 3 ints, i'am giving it x and y so now it needs one more to return another int, the final result. Why it this logic not correct? I can't make any sense of the actual output, specially with the polymorfic values when i forced parameters in f to be integers.

# let f (x : int) (y : int) (z : int) = x + y + z;;
val f : int -> int -> int -> int = <fun>
# let calc x y f = f x y;;
val calc : 'a -> 'b -> ('a -> 'b -> 'c) -> 'c = <fun>
gallais

In the expression let calc x y f = f x y;;, f is a locally-bound variable (calc binds x, y and then f) rather than the function you have defined before.

If you had written let calc x y = f x y;; then you'd have the expected result.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related