📄 timer.hs
字号:
-- | General purpose timers.module Language.Atom.Common.Timer ( Timer , timer , start , whenDone , periodicTimer ) whereimport Language.Atom-- | A Timer.data Timer = Timer (Var Int)-- | Creates a new timer, with a name and a count.timer :: Name -> System Timertimer name = scope name $ do timer <- int "timer" 0 rule "decrement" $ do when $ value timer >. 0 timer <== value timer - 1 return $ Timer timer-- | Starts a Timer. A Timer can be restarted at any time.start :: Timer -> Int -> Action ()start (Timer t) time = do lift $ assert "positiveTime" $ time >= 0 t <== intC (max 0 (time - 1))-- | Guard condition enabled with Timer completes.whenDone :: Timer -> Action ()whenDone (Timer t) = when $ value t ==. 0-- | Creates a periodic, free runnning timer. Returns a guard condition when Timer resets.periodicTimer :: Name -> Int -> System (Action ())periodicTimer name count = scope name $ do assert "positiveNumber" $ count >= 0 t <- timer name rule "reset" $ do whenDone t start t count return $ whenDone t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -