S. Alexander Jacobson wrote:
I want to read strings that look like "2"  or
"hello" into values of type Integer or String.
The problem is that read requires that strings be
read as "\"hello\"".  Is there a way either to
convince read to not require wrapping quotation
marks or, alternetively, to catch a read
exception, and do something sane?

"reads" is probably what you are looking for:


   Prelude> (reads :: ReadS Integer) ""
   []
   Prelude> (reads :: ReadS Integer) "a"
   []
   Prelude> (reads :: ReadS Integer) "2"
   [(2,"")]
   Prelude> (reads :: ReadS Integer) "123blah"
   [(123,"blah")]

And reading a string the way you want is best done by "id". :-)

Cheers,
   S.

_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to