Guest User

Untitled

a guest
Jan 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. module Main where
  2.  
  3. import Control.Monad (when)
  4. import Control.Monad.IO.Class (liftIO)
  5. import Data.IORef (newIORef, readIORef, writeIORef)
  6.  
  7. import Procedural (for_)
  8.  
  9. main :: IO ()
  10. main = do
  11. n <- newIORef (0 :: Int)
  12. for_ [1 .. 9] $ \i exit -> do
  13. n' <- liftIO $ readIORef n
  14. let n'' = n' + i
  15. when (n'' > 40) exit
  16. liftIO $ writeIORef n n''
  17. n' <- readIORef n
  18. print n'
Add Comment
Please, Sign In to add comment