A while back I brought up the idea of adding custom warning "classes", allowing such functions to be tagged partial. I should probably put together a proper proposal now that we have that process. Personally, I'd love to remove read from the Prelude, but that would be hard.
+1
+1
+1
I would put it more strongly:
read should be applied only to strings that are known to have been produced by methods of the Show class.
It's still the right way to handle error reporting for Read.
Very wrong:
do
x <- read <$> getInput
use x
Correct, in some contexts, but extremely lousy:
do
x <- read <$> getInput
evaluate (force x)
use x
Correct, but uninformative:
do
Just x <- readMaybe <$> getInput
use x
Correct and informative:
do
ip <- readEither <$> getInput
either (throwIO . parseError) use ip
(For some value of parseError)
Or, when reasonable,
do
ip <- readEither <$> getInput
either (\m -> displayMessage m *> tryAgain) ip