0
votes

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.

2
do xs <- stuff; mapM_ doThings xs? What exactly are you trying to do. Also: [()] is a pretty useless type. Isn't an Int enough? Or can't you just have the type String -> IO ()?Bakuriu
Thanks! I changed [()] to () and used mapM_, it worked great!Sandy Vanderbleek
You could keep [()] (assuming you have some reason to want that) by using mapM. Notice the trailing _ in Haskell typically means "ignore the result(s)".Thomas M. DuBuisson

2 Answers

1
votes

With your original types, you can do:

stuff >>= mapM_ doThings

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

0
votes

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

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