[Haskell-cafe] Converting String
Ketil Malde
ketil+haskell at ii.uib.no
Mon Jan 26 09:01:29 EST 2004
Alex Gontcharov <alexg005 at hotmail.com> writes:
> I'm fairly new to Haskell, I'd like to know how to convert
> a list of Strings of type IO [String] to Int.
Ah... an IO [String] is *not* a list of strings, it is an IO action
that can produce a list of strings. You can only get at the strings
inside the IO monad.
> I used map read p, where p is a list of IO Strings ["1", "2"]
p >>= (return . map read)
Or using do notation
do
x <- p
let z = map read x
gives you IO [Int] from your IO [String], but there's no¹ escape from
IO.
PS: You probably need a few type annotations to make the above work.
-kzm
¹ Well, there is, really, but we don't like to talk about it much :-)
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list