3 ms·
And in Haskell (feel free to include this): import Control.Concurrent (threadDelay) import System.IO main
by eutectic 11y ago
And in Haskell (feel free to include this):
import Control.Concurrent (threadDelay)
import System.IO
main :: IO ()
main = withFile "/sys/class/leds/beaglebone:green:usr0/brightness" AppendMode go
where put h s = hPutStrLn h s >> threadDelay 2000000
go h = let m = put h "0" >> put h "1" >> m in m
- codygman 11y agoWhy: go h = let m = put h "0" >> put h "1" >> m in m Rather than: go h = put h "0" >> put h "1" Oh, recursion...
- mcconnma 11y agoThanks, any thoughts on why I get this? $ ghc -o blink blink.hs [1 of 1] Compiling Main ( blink.hs, blink.o ) blink.hs:7:22: parse error on input `='
- eutectic 11y agoNot sure; I copy-pasted it back from hackernews and it works fine for me.
- gergoerdi 11y agoAs always, prefer prebuilt recursion scheme combinators instead of making your own. The following, using `forever`, is IMO much more readable because you don't have to mentally resolve the recursion: main :: IO () main = withFile ledFile AppendMode $ \h -> do let put s = hPutStrLn h s >> threadDelay 2000000 forever $ do put "0" put "1" where ledFile = "/sys/class/leds/beaglebone:green:usr0/brightness"