module Main ( main ) where import Language.Atom main :: IO () main = do -- Compile the 'counter' system with a sample rate of 20 msec. program <- compile "counter" 0.020 counter -- Generate a Simulink representation of the program. simulink program -- Generate a C representation of the program. c program counter :: System () counter = do -- A counter variable with an initial value of 0 (32-bit signed int). counter <- int "counter" 0 -- A reset input (bool). reset <- input bool "reset" -- A rule to increment the counter until it reaches 255. rule "incrTo255" $ do when $ value counter /=. 255 counter <== value counter + 1 -- A rule to reset the counter if the counter is 255 and reset is true. rule "resetCounter" $ do when $ value counter ==. 255 when reset counter <== 0 -- Assert the counter is always less than 255 -- which is not correct. assert "counterLessThan255 yes, this should happen" $ value counter <. 255 -- Assert the counter is always greater than 0 -- also not correct. assert "counterMoreThan0 yes, this should happen" $ value counter >. 0