我有:
stuff :: IO [String]
doThings :: String -> IO [()]
我想
stuff >>= doThings
但我的类型已关闭。我基本上想做一个解除绑定,但我尝试的一切都是微妙的错误。
我有:
stuff :: IO [String]
doThings :: String -> IO [()]
我想
stuff >>= doThings
但我的类型已关闭。我基本上想做一个解除绑定,但我尝试的一切都是微妙的错误。
使用您的原始类型,您可以执行以下操作:
stuff >>= mapM_ doThings
如果您将 doThings 更改为具有类型,这也有效doThings :: String -> IO ()
如果你有很多这样的功能,这是教科书用例ListT
:
main = runListT $ do
string <- ListT stuff
ListT $ doThings string