If the input argument are not as expected I want to exit the program. How should I achieve that? Below is my attempt.
let () =
if ((Array.length Sys.argv) - 1) <> 2 then
exit 0 ; ()
else
()
Thanks.
exit n
is a right way to exit program, but your code has a syntax error. if ... then exit 0; ()
is parsed as (if ... then exit 0); ()
. Therefore you got a syntax error around else
, since it is not correctly paired with then
.
You should write:
let () =
if ((Array.length Sys.argv) - 1) <> 2 then begin
exit 0 ; ()
end else
()
or simply,
let () = if Array.length Sys.argv - 1 <> 2 then exit 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With