Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import Control.Monad (when)
- import Control.Monad.IO.Class (liftIO)
- import Data.IORef (newIORef, readIORef, writeIORef)
- import Procedural (for_)
- main :: IO ()
- main = do
- n <- newIORef (0 :: Int)
- for_ [1 .. 9] $ \i exit -> do
- n' <- liftIO $ readIORef n
- let n'' = n' + i
- when (n'' > 40) exit
- liftIO $ writeIORef n n''
- n' <- readIORef n
- print n'
Add Comment
Please, Sign In to add comment