timer.hs
来自「Cores are generated from Confluence a mo」· HS 代码 · 共 48 行
HS
48 行
-- | 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 + =
减小字号Ctrl + -
显示快捷键?