'read' throws; why not maybe or either?

Is there a variation of 'read' which uses Maybe or Either to handle failure instead of an exception?

On 24/11/13 21:49, Patrick Redmond wrote:
Is there a variation of 'read' which uses Maybe or Either to handle failure instead of an exception?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
See http://stackoverflow.com/questions/5121371/how-to-catch-a-no-parse-exception... -- Mateusz K.

You might be interested in the 'safe' package. It has a function in it
called readMay, along with a lot of other useful minor omissions from
prelude. http://hackage.haskell.org/package/Safe-0.1/docs/Safe.html
On Sun, Nov 24, 2013 at 4:49 PM, Patrick Redmond
Is there a variation of 'read' which uses Maybe or Either to handle failure instead of an exception? _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On 11/24/2013 04:49 PM, Patrick Redmond wrote:
Is there a variation of 'read' which uses Maybe or Either to handle failure instead of an exception?
readMaybe: http://hackage.haskell.org/package/base-4.6.0.1/docs/Text-Read.html#v:readMa... Prelude> import Text.Read (readMaybe) Prelude Text.Read> readMaybe "Hello, World!" :: Maybe Int Nothing Prelude Text.Read> readMaybe "45" :: Maybe Int Just 45

Thanks all! I was able to make use of readEither to do just what I wanted. On Tuesday, November 26, 2013, Michael Orlitzky wrote:
On 11/24/2013 04:49 PM, Patrick Redmond wrote:
Is there a variation of 'read' which uses Maybe or Either to handle failure instead of an exception?
readMaybe:
http://hackage.haskell.org/package/base-4.6.0.1/docs/Text-Read.html#v:readMa...
Prelude> import Text.Read (readMaybe) Prelude Text.Read> readMaybe "Hello, World!" :: Maybe Int Nothing Prelude Text.Read> readMaybe "45" :: Maybe Int Just 45
_______________________________________________ Beginners mailing list Beginners@haskell.org javascript:; http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
David McBride
-
Mateusz Kowalczyk
-
Michael Orlitzky
-
Patrick Redmond