Last active
June 14, 2021 15:58
-
-
Save nikoheikkila/483d3492dbe4dc879ddf to your computer and use it in GitHub Desktop.
Haskell: Module that repeats any IO action n times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Repeater where | |
| -- General usable module that repeats any IO action n times. | |
| -- by Niko Heikkilä | |
| repeatIOAction :: Int -> IO () -> IO () -- Inputs: integer and IO. Outputs: IO | |
| repeatIOAction 0 _ = return () -- exit recursive loop here | |
| repeatIOAction n action = do | |
| action -- action to perform | |
| repeatIOAction (n-1) action -- decrement n to make it recursive | |
| -- Example: print a string "Hello World" 10 times to console | |
| main = repeatIOAction 10 (putStrLn "Hello World") | |
| -- | END OF MODULE | -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment