1 module Sim (simulate, Circuit, simulateIO) where
4 simulate f input s = do
7 putStr "\nInitial State: "
10 foldl1 (>>) (map (printOutput) output)
12 output = run f input s
14 -- A circuit with input of type a, state of type s and output of type b
15 type Circuit a s b = a -> s -> (s, b)
17 run :: Circuit a s b -> [a] -> s -> [(s, b)]
19 (s', o): (run f input s')
24 simulateIO :: (Read a, Show b, Show s) => Sim.Circuit a s b -> s -> IO()
26 putStr "Initial State: "
31 runIO :: (Read a, Show b, Show s) => Sim.Circuit a s b -> s -> IO()
38 let i = (read line) in do
39 let (s', o) = f i s in do
43 printOutput :: (Show s, Show o) => (s, o) -> IO ()
44 printOutput (s, o) = do
47 putStr "\nNew State: "
50 -- vim: set ts=8 sw=2 sts=2 expandtab: