Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml Currying/ Multiple arguments

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?

like image 309
ECE Avatar asked Jan 19 '14 20:01

ECE


1 Answers

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.

like image 193
iguerNL Avatar answered Sep 19 '22 09:09

iguerNL