0

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

6
  • Why would it? You're not running the inner function. I bet you're also getting a warning about an unused value. You should heed that warning and either use the returned value or explicitly ignore it with a type annotation. That would give you a much more useful error. Commented Apr 22, 2021 at 16:51
  • @glennsl, what command are you using to display all the warnings? Commented Apr 22, 2021 at 17:35
  • 1
    On the command line, you can use -w +A, if you are using ocamlc or ocamlopt directly. In the file itself adding [@@@warning "+A"] at the top of the file will be equivalent. And Dune has a better set of warning enabled by default. Commented Apr 22, 2021 at 17:48
  • 1
    The unused-var warning is enabled by default, so you shouldn't need to do anything. Turning on all warnings isn't a bad idea though. Or even -warn-error +A to turn them into errors. Commented Apr 22, 2021 at 17:56
  • 1
    @octachron Ah, I was originally referring to the h variable though, which also does not seem to be used as its type is not what one would expect from the function. Commented Apr 22, 2021 at 20:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You need to use the list argument of main.
Indeed, this is one of the solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.