Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Warning due to semicolon

I run a hello world program below

let x=3;

print_string "hello world!";;

and got this warning:

File "hello.ml", line 1, characters 6-7:
1 | let x=3;
          ^
Warning 10 [non-unit-statement]: this expression should have type unit.

How can I fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Recall from the answers to your previous questions that ; is a sequence operator, not a statement terminator. Your code will therefore be interpreted as:

let x = (3; print_string "hello world!")

which is equivalent to:

let x = print_string "hello world!"

Meaning that you’re throwing away the 3, and x will have type unit because that’s what print_string returns. You can "fix it", i.e. get rid of the warning, by using the second form above.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading