L.Leo
L.Leo

Reputation: 63

ocaml function applied too many arguments

i try the below code to do a recursive from i -> 0 and output white space

let print_tab fmt i = 
    match i with
    | 0 -> put fmt "%s" "" 
    | _ -> put fmt "%s" "    " ; print_tab fmt (i-1)

however it does not work, show the error like below

 Error: This function is applied to too many arguments;
 maybe you forgot a `;'

i have try another code

let print_tab fmt = function
    | 0 -> put fmt "%s" "" 
    | j -> put fmt "%s" "    " ; print_tab fmt (j-1)

but it get the same error, what's wrong?

Upvotes: 0

Views: 767

Answers (1)

Thomash
Thomash

Reputation: 6379

The error is that you forgot rec so your function is not recursive and tries to use a previously defined version of print_tab.

Upvotes: 3

Related Questions