6
votes

I have a simple function:

 let rec ap x y = if x < 10 then 12 else ap((x-1) (y));;

but the error I keep on getting is:

Error: This expression has type int
   This is not a function; it cannot be applied.

I've been stuck on this for 2 hours now, i can not figure out why this does not work?

Also i just simplified the function, because in my actual ocaml code, the problem boils down to this. I'm not sure if this has to do with currying, but Can someone please explain why this is happening?

1
The actual error message indicates the exact location of the problem, which is (x-1).Martin Jambon

1 Answers

6
votes

The OCaml compiler considers that you are applying (x-1) to (y) in ((x-1) (y)). This is why you get the error: "This expression has type int. This is not a function; it cannot be applied."

Actually, you have to write ap (x-1) (y), because ap takes two arguments.

Remember that in OCaml (Or other Hindley–Milner derived languages: SML, Haskell) parenthesis are not needed to apply functions and serve a different purpose as opposed to C like languages.