Created
April 27, 2012 19:24
-
-
Save jargv/2512042 to your computer and use it in GitHub Desktop.
Accumulating string values across in a map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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