packages feed

leaky-0.1.0.0: leaky-min-cppd-working.hs

  -- This leaks with GHC 7.8.3 -O2, strict field notwithstanding.

  {-  OPTIONS_GHC -O2 #-}
  {-# OPTIONS_GHC -O0 #-}

  module Main ( main ) where

  import Types_min

  toggle (St b) = St (not b)

  {-# ANN module (SeqaidAnnExclude "toggle") #-}
  {-# ANN module (SeqaidAnnExclude "duration") #-}
  {-# ANN module (SeqaidAnnExclude "period") #-}
  {-# ANN module (SeqaidAnnExclude "main") #-}

  duration = 5000000  -- XXX tune for your hardware
  period = duration `div` 10

  main = do
    putStrLn "Leaky started."
    rslt <- duty (St False) 0
    (return $! rslt) >>= return
    putStrLn "Finished."

  duty :: State -> Int -> IO State
  duty state i = do
    let state' = toggle state
    if 0 == i `mod` period then return () else return ()
    if i < duration then duty state' (1+i) else return state'
  {-# NOINLINE duty #-}