[Haskell-beginners] using "read"

Iustin Pop iusty at k1024.org
Fri Jan 15 14:02:44 EST 2010

On Fri, Jan 15, 2010 at 07:49:40PM +0100, Luca Ciciriello wrote:
> Hi All.
> in the function:
> func :: String -> Int
> func str = read str
> An absolute beginner as i am, want to use "read" to convert a String
> in a Int, but I don't know how to protect my function func from an
> exception when str is not a number like "12A". How can I do?
> Thanks in advance for any answer to this my simply question.

I have tried to solve this problem too, and I ended up using the
function "reads", which gives you back information about the parse

Hope this helps,

More information about the Beginners mailing list