You may want to use reads
as read will call error if the
string is not an integer
or use something akin to the example below
readMaybeInt :: String -> Maybe Int
readMaybeInt s = case reads s of
[(x,_)] -> Just x
_ -> Nothing
-----Original Message-----
From: Hal Daume III [mailto:[EMAIL PROTECTED]]
Sent: 07 February 2002 17:54
To: DK
Cc: [EMAIL PROTECTED]
Subject: Re: String manipulation.
You should have a look at the Read class. A member a of the Read class
has a function read :: String -> a.
so, for example, you can say:
(read "5.0") :: Double
to read this as a double. You could also read it as an integer or
something.
If you have a list of strings that you want to convert to a list of
integers, you could do:
map (\x -> (read x)::Double) [list of strings]
Hope that helps.
- Hal
--
Hal Daume III
"Computer science is no more about computers | [EMAIL PROTECTED]
than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
On Thu, 7 Feb 2002, DK wrote:
> Hello. First of all I am a beginner in Haskell, and I must confess I do not yet fully understand it. I need to write a program in Haskell, though, and I am having some difficulties...
>
> What I would like to ask, is how can I take a string from a list, and manipulate it, in order to convert it to an integer. Any help would be very appreciated.
>
> Thank you very much,
> Dimitris
>
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell