Proposal: die to System.Exit (and/or Prelude)
Vo Minh Thu
noteed at gmail.com
Sat Dec 14 11:09:20 UTC 2013
2013/12/14 Simon Hengel <sol at typeful.net>:
> Hi!
> I propose to add
>
> die :: String -> IO ()
> die err = hPutStrLn stderr err >> exitFailure
>
> to System.Exit.
>
> Reasoning:
>
> (1) It's a frequently required functionality. Almost every command-line
> program has code similar to this.
>
> (2) The definition is relatively short, but in addition to the
> definition, you need two import statements.
>
> (3) It's frequently done wrong (e.g. writing to stdout instead of
> stderr, or not using exitFailure, or both).
>
> I haven't done any extensive research on Hackage, but I quickly looked
> at Haddock. Here we have a definition of die [1], but we also print to
> stdout at a couple of place and then call exitFailure [2].
>
> Personally, I think it should be re-exported from Prelude. But this may
> be controversial. So let's have two separate votes:
Isn't your `die` function a special case of `error :: String -> a`,
which is in the Prelude ?
I think variants of what you propose are often used: different exit
codes, not exiting and flushing stderr, displaying an arbitrary `Show
a` instead of `String`, using `Text`, and so on.
Actually I think some (all ?) `IO` things from the Prelude should not
be in the Prelude. For instance I may want to use the `bytestring`
`readFile`.
- 1 (for both)
Thu
More information about the Libraries
mailing list