Mercurial > hg > Members > toma > osc2013
view prog/counter.hs @ 8:3ee3f33bc368
fix
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 06 Jul 2013 12:38:28 +0900 |
parents | e9af42a3707b |
children |
line wrap: on
line source
{-# LANGUAGE OverloadedStrings #-} import Network.Wai import Network.HTTP.Types (status200) import Network.Wai.Handler.Warp (run) import Control.Monad.Trans (lift) import Data.IORef (newIORef, atomicModifyIORef) import Data.ByteString.Lazy.UTF8 (fromString) application counter request = do count <- lift $ incCount counter return $ responseLBS status200 [("Content-type", "text/html")] $ fromString $ show count incCount counter = atomicModifyIORef counter (\c -> (c+1, c)) main = do counter <- newIORef 0 run 3000 $ application counter