Hi all,
I have written a simple proposal that would allow for the value yielded by main
to set the program’s exit status, in a well-typed way. The committee has requested more feedback from users, if you have an opinion on this either way (especially if you’re a new user or are frequently involved in teaching Haskell) your feedback would be appreciated!
From the motivation section:
Many languages, perhaps most notably C, allow specifying a program’s exit
code by returning an appropriate value from main. Haskell98 does
allow a main which yields values of any type, but surprisingly it does not
do anything with the result: any successful execution will result in a successful
program exit, even if main yields 1 orExitFailure 1
.Before this proposal, the following program would exit with code 0 even
when there are no results:main :: IO ExitCode main = do results <- doSomeWork case results of [] -> pure (ExitFailure 1) _ -> print results >> pure ExitSuccess
With this proposal in place, the program would exit with code 1 in that
case.This proposal follows Rust in using a typeclass for return types which can signal exit codes.
This is a minor quality of life improvement, but one that I’ve seen hit
newcomers now and then and matches reasonable expectations of program
behavior.