2011-05-26 97 views
1

您好,我需要幫助haskell中的map函數和IO操作。與haskell中的IO映射?

我有一個像[(x,(y,z))]一個名單,我想給一個函數列表中的每個項目,所以我想用map問題是,該函數的樣子:

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

但是當我嘗試使用地圖(map test myList)我得到一個錯誤,因爲它是IO,如何解決這個問題?

回答

5

您是否嘗試過使用mapM(來自Control.Monad)?

(對不起,沒有更多的代碼,我只能猜測)

2

因爲test駐留在IO單子,你將不得不使用mapM看到here,詳情herehere

+1

第二個鏈接很棒。我從來沒有發現過。 – 2011-05-26 17:28:32