Skip to content

Instantly share code, notes, and snippets.

@nikoheikkila
Last active June 14, 2021 15:58
Show Gist options
  • Select an option

  • Save nikoheikkila/483d3492dbe4dc879ddf to your computer and use it in GitHub Desktop.

Select an option

Save nikoheikkila/483d3492dbe4dc879ddf to your computer and use it in GitHub Desktop.
Haskell: Module that repeats any IO action n times
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