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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With