简体   繁体   中英

Haskell: monad stack bind with IO and []

I have:

stuff :: IO [String]
doThings :: String -> IO [()]

and I want to

stuff >>= doThings

but my types are off. I want to do a lifted bind essentially but everything I try is subtly wrong.

With your original types, you can do:

stuff >>= mapM_ doThings

This also works if you change doThings to have type doThings :: String -> IO ()

If you've got lots of such functions, this is the textbook usecase of ListT :

main = runListT $ do
  string <- ListT stuff
  ListT $ doThings string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM