Question:Why can’t I compile a program with unused variables in Ocaml?
let foo a b = a + b
— Error (warning 32 [unused-value-declaration]): unused value foo.
Answer:You can disable the promotion of the warning to an error by customizing the flags in your dune file:
or disabling the promotion with an attribute in the file itself
(flags (:standard -warn-error "-unused-value-declaration"))
or for just the value:
(and you can use
let[@warnerror "-unused-value-declaration"] x = ()
@warningfor disabling the warning itself rather than its promotion to an error.)
It is also possible to use a leading underscore to indicate the intent that a value is purposefully unused:
Nevertheless, I find this warning generally useful to avoid dead code in the source code and I would not recommend to disable it.
let _x = ()
If you have better answer, please add a comment about this, thank you!
If you like this answer, you can give me a coffee by <a href=”https://violencegloss.com/mkw7pgdwwr?key=2a96ade6f3760c7e63343a320febb78e”>click here</a>