Numeric literals
Patrik Jansson
patrikj@cs.chalmers.se
Tue, 28 Aug 2001 14:57:38 +0200 (MET DST)
On Tue, 28 Aug 2001, Mark Carroll wrote:
> How do I tell if an instance of reading will work, or catch that it
> didn't?
Short: check the resulting list from reads "some string"
In the Read class we have also
reads :: Read a => ReadS a
type ReadS a = String -> [(a,String)]
[A ghci test session follows]
Prelude> reads "123.45a" :: [(Float,String)]
[(123.45,"a")]
Prelude> reads "123a.45" :: [(Float,String)]
[(123.0,"a.45")]
Prelude> reads "a123.45" :: [(Float,String)]
[]
Prelude> reads "Infinity" :: [(Float,String)]
*** Exception: Ratio.%: zero denominator
/Patrik