
28 Aug
2001
28 Aug
'01
12:57 p.m.
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