Guest User

Untitled

a guest
Dec 11th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Graphics.UI.WX
  2. import Data.IORef
  3.  
  4. main :: IO ()
  5. main = start $ do
  6.   f <- frame [text := "Type speed meter"]
  7.   input <- textCtrl f []
  8.   status <- statusField []
  9.   set f [statusBar := [status]]
  10.   t <- timer f [interval := 1000]
  11.   tick <- newIORef (0 :: Int)
  12.   lastPressed <- newIORef []
  13.   pressed <- newIORef (0 :: Int)
  14.   let doStuff = do
  15.         modifyIORef tick (+1)
  16.         return ()
  17.         lastTick <- readIORef tick
  18.         modifyIORef lastPressed $ filter (> (lastTick - 15))
  19.         currRate <- fmap ((*4) .length) $ readIORef lastPressed
  20.         overallRate <- fmap ((`div` lastTick) . (*60)) $ readIORef pressed
  21.         set status [text := "Current: " ++ show currRate ++ " Overall: " ++ show overallRate]
  22.        
  23.   let onKeyPress = do
  24.         modifyIORef pressed (+1)
  25.         lastTick <- readIORef tick
  26.         modifyIORef lastPressed (lastTick : )
  27.         propagateEvent
  28.        
  29.   set t [on command := doStuff]
  30.   set input [on anyKey := const onKeyPress]
  31.   return ()
Advertisement
Add Comment
Please, Sign In to add comment