Proposal: die to System.Exit (and/or Prelude)
Herbert Valerio Riedel
hvr at gnu.org
Mon Dec 16 09:53:21 UTC 2013
Hello Simon,
On 2013-12-14 at 11:56:11 +0100, Simon Hengel wrote:
> I propose to add
>
> die :: String -> IO ()
> die err = hPutStrLn stderr err >> exitFailure
>
> to System.Exit.
Why not simply use the existing `fail :: String -> IO a` method instead?
The differences & similiarities I see wrt `fail`:
- `die` throws an `ExitCode` exception, whereas `fail` throws an
`IOError` exception
- Both result in the message written to stderr and a non-zero exit code
- As both use exceptions, `die` does guarantee termination (as it can
be caught)
- `die` writes to stderr at invocation time, whereas `fail` attaches
the message to the exception, which is then output by the top
exception handler.
Due to that, catching a `die`-caused exception will print the
termination message even though the process-exit was
cancelled. Whereas attaching the message to the exception allows for
more flexibility as well as for atomicity wrt message-output and
termination.
- `fail` is available from Prelude (and part of Haskell98/2010),
whereas `System.Exit.die` would require an import of "System.Exit"
(with the small risk of breaking code that expects only
Haskell2010-known entities exported by "System.Exit")
Therefore I'm not convinced (yet), that the suggested `die`
implementation has sensible semantics in the context of exceptions, and
that it offers enough benefits over the already existing `fail` method.
Cheers,
hvr
More information about the Libraries
mailing list