Useful-0.0.6: Some useful functions and shorthands.



IO operations, part of the Useful module.



replicateM :: Monad m => Int -> m a -> m [a]Source

repeats an IO function n number of times.

replicateM_ :: Monad m => Int -> m a -> m ()Source

Like replicateM but stores the returns

foreach :: Monad m => [a] -> (a -> m b) -> m ()Source

repeats an IO function for every member of a list, using the list item as an arguement

 $ do foreach [1..3] print
 $ do foreach "asjkdnsd" putChar

while :: Monad m => m Bool -> m a -> m ()Source

repeats an IO function until a IO Bool is true

NOTE: Be careful with this function! Better to use recursion. Testing against an item created in the loop will not work.

put :: Show a => a -> IO ()Source

like putStr or putChar but works on any type with "show" defined in a similar way to how print does. Can be thought of as "print" without the trailing linebreak.

NOTE: This means it will print strings with quotes around them. To print strings without quotes use putStr or putStrLn

write :: Show a => a -> IO ()Source

Alias of put

writeln :: Show a => a -> IO ()Source

Alias of print

putln :: Show a => a -> IO ()Source

Alias of print

mapM_2 :: Monad m => (a -> m b) -> [[a]] -> m ()Source

maps an IO function in depth N to the given list. Also versions without _ for storing of the returns.

Again there are also mapM_3, mapM_4 and mapM_5 defined (as well as versions without underscores)

 $ mapM_2 write [[1,2,3,4,5],[1,2]]

rand :: [a] -> IO aSource

takes a list and returns a random element from that list

 $ rand [1..5]
 $ rand "hello there people"