Created
October 19, 2017 16:02
-
-
Save waf/178a33f8b331e1e6c0481231d2d758f8 to your computer and use it in GitHub Desktop.
Plank script in idris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Counter app, count up in 30 seconds increments, and | |
-- then count down the last 10 seconds | |
module Main | |
import System | |
-- given a second, what should we say at that second? | |
sayWhatAt : Int -> String | |
sayWhatAt 30 = "30 seconds passed" | |
sayWhatAt 60 = "1 minute passed" | |
sayWhatAt seconds = | |
case seconds `mod` 60 of | |
0 => minutes ++ " minutes passed" | |
30 => minutes ++ " 30 passed" | |
n => "" | |
where | |
minutes : String | |
minutes = show (seconds `div` 60) | |
-- generate the list that counts up every 30s, then does the final countdown | |
generateTimings : Int -> List String | |
generateTimings t = | |
let startCountdown = t - 10 in | |
let countUp = map sayWhatAt [1..startCountdown-1] | |
countDown = map show [10..1] in | |
countUp ++ countDown | |
-- print every item in the list, sleeping for 1s after printing | |
-- both usleep and print result in IO | |
speakTimings : List String -> IO () | |
speakTimings [] = putStrLn "" | |
speakTimings (t::ts) = do | |
putStrLn t | |
usleep 1000000 | |
speakTimings ts | |
main : IO () | |
main = do | |
putStrLn "Hi everyone, ready? Start planking in 5, 4, 3, 2, 1" | |
speakTimings (generateTimings 100) | |
putStrLn "Good job everyone! I knew you could do it!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment