<div dir="ltr"><blockquote class="gmail_default gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I am a little worried about breaking programs that end in an
innocent-looking `return 0`, just because some other languages like to
end programs with that phrase
</blockquote><div><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">The proposal specifies that such a program returns `ExitSuccess`, but adds a warning. That seems OK to me; it does not break the program.</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Oh -- maybe you mean that `return 1` means "return with exit code 1" today. Is that really true? I don't think so.</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Overall this proposal seems fine to me. I'd be happy to see it done.</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Simon<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 29 Feb 2024 at 12:38, Richard Eisenberg <<a href="mailto:reisenberg@janestreet.com">reisenberg@janestreet.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I haven't followed this proposal closely. But couldn't we have a transition period toward this eventual goal? That is, introduce a new warning, on by default, if `main` returns anything other than `()`. That goes for a few releases. Then we require that the return type of main has an instance of ExitStatus.<div><br></div><div>I'm not worried about changing the behavior of programs that have type IO ExitCode but expect the program to return 0 unconditionally; that's just begging for confusion. I am a little worried about breaking programs that end in an innocent-looking `return 0`, just because some other languages like to end programs with that phrase. So I'm not sure if we should have an instance ExitStatus Int (or instance ExitStatus Integer) -- but we probably should. If a program ends with `return 1`, the programmer probably wants the OS to return 1 as well.</div><div><br></div><div>Richard</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 29, 2024 at 5:29 AM Arnaud Spiwack <<a href="mailto:arnaud.spiwack@tweag.io" target="_blank">arnaud.spiwack@tweag.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Dear all,</div><div><br></div><div>Shea Levy proposes to do something with the values returned by `main` <a href="https://github.com/ghc-proposals/ghc-proposals/pull/631" target="_blank">https://github.com/ghc-proposals/ghc-proposals/pull/631</a> .<br></div><div><br></div><div>The problem is that `main` is allowed to be of type `IO A` for any `A`. And GHC will simply drop the value returned by `main`. Shea contends that it's surprising. I agree that dropping a value without the compiler being explicitly instructed to is surprising. But Shea says that when `A` is `ExitCode` this is even more surprising. Namely `main :: IO ExitCode; main = return $ Failure 1` actually terminates with exit code 0. And I doubt that it's what anybody expects when reading the code.</div><div><br></div><div>The proposal is simple, but I have a lot of comments on it. Sorry about that…<br></div><div><br></div><div>Now, this sort of proposal is tricky. When the current behaviour is confusing, we want to change the default. But putting the new default behind an extension doesn't really solve the fact that there's a trap. The extension is, therefore, unlikely to be well tested before it becomes part of the next language edition.</div><div><br></div><div>Shea's main proposition doesn't actually use an extension though. He adds a type class `ExitStatus`, and if `ExistStatus A`, then `main :: IO A` uses the instance to determine the exit code based on the return value.</div><div><br></div><div>The only change to the current behaviour is that `main :: IO ExitCode` instead of always terminating with exit code 0 when returning now terminates with the expected error code. The argument for not putting this behind an extension is that virtually anybody affected by the change will actually have the behaviour they were expecting. But maybe the argument isn't strong enough (the changes may be more “interesting” if some library exports some `ExistStatus` instance).<br></div><div><br></div><div>This design of this proposal is inspired by Rust's design. I've asked our Rust team, and they certainly seem to have internalised the idea of returning an exit code. It really seems a pretty natural feature to have. So I'm rather in favour of some flavour of the type class implementation. Though have a look at the alternatives, where you'll find other approaches such as restricting the type of `main` to unsurprising types.</div><div><br></div><div>One caveat with respect to the main proposal: it is proposed that when no `ExistStatus A` is found, then we drop the returned value like today. I don't know that it's quite easy to implement this behaviour. But it can be recovered by a catch-all overlapping instance, so maybe it's a better way to specify the desired behaviour.<br></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Arnaud Spiwack<br>Director, Research at <a href="https://moduscreate.com" rel="noopener noreferrer" target="_blank">https://moduscreate.com</a> and <a href="https://tweag.io" rel="noopener noreferrer" target="_blank">https://tweag.io</a>.</div></div></div>
_______________________________________________<br>
ghc-steering-committee mailing list<br>
<a href="mailto:ghc-steering-committee@haskell.org" target="_blank">ghc-steering-committee@haskell.org</a><br>
<a href="https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee" rel="noreferrer" target="_blank">https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee</a><br>
</blockquote></div>
_______________________________________________<br>
ghc-steering-committee mailing list<br>
<a href="mailto:ghc-steering-committee@haskell.org" target="_blank">ghc-steering-committee@haskell.org</a><br>
<a href="https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee" rel="noreferrer" target="_blank">https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee</a><br>
</blockquote></div>