Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created November 23, 2015 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/84a65d627a36b00578e8 to your computer and use it in GitHub Desktop.
Save chuck0523/84a65d627a36b00578e8 to your computer and use it in GitHub Desktop.
import Control.Monad
import Data.IORef
main = do
printList [1..5]
s <- getSum [6..10]
print s
printList ls = do
forM_ ls $ \i -> do
print i
getSum ls = do
s <- newIORef 0
forM_ ls $ \i -> do
c <- readIORef s
writeIORef s (c + i)
ret <- readIORef s
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment