Andrej Hatzi
Andrej Hatzi

Reputation: 342

Ocaml recursion not printing int when inside another Function

When I compile and Execute this piece of code. It prints nothing.

 let main list = 
        let rec xyz list = 
            match list with
            |[]->[]
            |m::body -> 
            begin
            print_int m;
            xyz body 
            end
        in xyz
    
    let h = main [1;2;3]

If xyz is used outside of main is working without any error and printing 1 2 and 3

Upvotes: 0

Views: 99

Answers (1)

octachron
octachron

Reputation: 18892

Compiling your code with all warning enabled yields the following warning:

1 | let main list =
             ^^^^
Warning 27 [unused-var-strict]: unused variable list.

And indeed, the argument list is unused by main since in

let main list =
  let rec xyz list =
    ...
  in
  xyz

you are returning the function xyz without applying it.

Upvotes: 2

Related Questions