Skip to content

Instantly share code, notes, and snippets.

@CindyLinz
Created March 3, 2013 14:44
Show Gist options
  • Save CindyLinz/5076364 to your computer and use it in GitHub Desktop.
Save CindyLinz/5076364 to your computer and use it in GitHub Desktop.
Another approach, still lazy. But without stack blowup.
{-# LANGUAGE BangPatterns #-}
module T where
import Control.Concurrent.MVar
main = do
countMVar <- newMVar (\ count -> count):: IO (MVar (Int -> Int))
let
process :: IO ()
process = do
cmd <- getLine
modifyMVar_ countMVar $ \ countEater -> return $ \ count -> countEater $! count + 1
if cmd == "out"
then modifyMVar_ countMVar $ \ countEater -> do
let
now = countEater 0
putStrLn $ show now
return $ \ count -> now + count
else return ()
process
process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment