develhevel
develhevel

Reputation: 3281

map with IO in haskell?

Hi I need help with the map function and IO operations in haskell.

I have a List like [(x,(y,z))] and i want to give a function each item of the list, so i want to use map the problem is, that the function looks like:

test :: (String, (String, String)) -> IO (String, String, (String, String))
test (a,(b,c)) = do
    -- some IO stuff
    return (a,b, (c,c))

but when i try to use map (map test myList) i get a error because it is IO, how to fix this?

Upvotes: 1

Views: 1132

Answers (2)

Landei
Landei

Reputation: 54584

Did you try to use mapM (from Control.Monad) instead?

(sorry, without more code I can only guess)

Upvotes: 6

Bas Bossink
Bas Bossink

Reputation: 9698

Because test resides in the IO monad you'll have to use mapM see here, here and here for details.

Upvotes: 3

Related Questions