Is there a traditional way to map a function using IO? In particular, I would like to map a function that returns a random value. Using a regular map will lead to the conclusion of type ([IO b]), but to unpack the values โโin the list from IO I need something like (IO [b]). So I wrote ...
mapIO :: (a -> IO b) -> [a] -> [b] -> IO [b] mapIO f [] acc = do return acc mapIO f (x:xs) acc = do new <- fx mapIO f xs (new:acc)
... which works great. But there seems to be a solution for this built in to Haskell. For example, a usage example:
getPercent :: Int -> IO Bool getPercent x = do y <- getStdRandom (randomR (1,100)) return $ y < x mapIO (\f -> getPercent 50) [0..10] []
io random haskell
unignorant
source share