
Hi, I'm fairly new to Haskell, I'd like to know how to convert a list of Strings of type IO [String] to Int. I used map read p, where p is a list of IO Strings ["1", "2"] Thanks

On Mon, 26 Jan 2004 18:05:16 +1030
Alex Gontcharov
Hi,
I'm fairly new to Haskell, I'd like to know how to convert a list of Strings of type IO [String] to Int. I used map read p, where p is a list of IO Strings ["1", "2"]
http://www.haskell.org/tutorial/ http://www.haskell.org/tutorial/io.html http://www.haskell.org/learning.html

Derek Elkins writes:
On Mon, 26 Jan 2004 18:05:16 +1030 Alex Gontcharov
wrote: I'm fairly new to Haskell, I'd like to know how to convert a list of Strings of type IO [String] to Int. I used map read p, where p is a list of IO Strings ["1", "2"]
http://www.haskell.org/tutorial/ http://www.haskell.org/tutorial/io.html http://www.haskell.org/learning.html
Also
http://www.haskell.org/hawiki/ThatAnnoyingIoType
http://www.haskell.org/hawiki/UsingIo
http://www.haskell.org/hawiki/UsingMonads
--KW 8-)
--
Keith Wansbrough

Alex Gontcharov
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
participants (4)
-
Alex Gontcharov
-
Derek Elkins
-
Keith Wansbrough
-
Ketil Malde