Skip to content

Instantly share code, notes, and snippets.

@jargv
Created April 27, 2012 19:24
Show Gist options
  • Save jargv/2512042 to your computer and use it in GitHub Desktop.
Save jargv/2512042 to your computer and use it in GitHub Desktop.
Accumulating string values across in a map
import Data.IORef
import qualified Data.Map as M
import Control.Monad(forever)
prompt msg = putStr msg >> getLine
main = do
ref <- newIORef M.empty
forever $ do
str <- prompt "enter a string:"
modifyIORef ref $ M.insertWith (+) str 1
print =<< readIORef ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment