projects
/
matthijs
/
master-project
/
cλash.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c075361
)
Show input on each simulation step.
author
Matthijs Kooijman
<m.kooijman@student.utwente.nl>
Fri, 30 Jan 2009 09:10:41 +0000
(10:10 +0100)
committer
Matthijs Kooijman
<m.kooijman@student.utwente.nl>
Fri, 30 Jan 2009 09:10:41 +0000
(10:10 +0100)
Sim.hs
patch
|
blob
|
history
diff --git
a/Sim.hs
b/Sim.hs
index 0820d1360935fed93e908879c54f1e2f2ca8f613..771896ffc2e8280470cf8ac741c0c5f099b3ee4b 100644
(file)
--- a/
Sim.hs
+++ b/
Sim.hs
@@
-14,35
+14,37
@@
simulate f input s = do
-- A circuit with input of type a, state of type s and output of type b
type Circuit a s b = a -> s -> (s, b)
-- A circuit with input of type a, state of type s and output of type b
type Circuit a s b = a -> s -> (s, b)
-run :: Circuit a s b -> [a] -> s -> [(
s, b
)]
+run :: Circuit a s b -> [a] -> s -> [(
a, b, s
)]
run f (i:input) s =
run f (i:input) s =
- (
s', o
): (run f input s')
+ (
i, o, s'
): (run f input s')
where
(s', o) = f i s
run _ [] _ = []
where
(s', o) = f i s
run _ [] _ = []
-simulateIO :: (Read a, Show b, Show s) => Sim.Circuit a s b -> s -> IO()
+simulateIO :: (Read a, Show
a, Show
b, Show s) => Sim.Circuit a s b -> s -> IO()
simulateIO c s = do
putStr "Initial State: "
putStr $ show s
putStr "\n\n"
runIO c s
simulateIO c s = do
putStr "Initial State: "
putStr $ show s
putStr "\n\n"
runIO c s
-runIO :: (Read a, Show b, Show s) => Sim.Circuit a s b -> s -> IO()
+runIO :: (Read a, Show
a, Show
b, Show s) => Sim.Circuit a s b -> s -> IO()
runIO f s = do
runIO f s = do
- putStr "\nInput
:
"
+ putStr "\nInput
?
"
line <- getLine
if (line == "") then
return ()
else
let i = (read line) in do
let (s', o) = f i s in do
line <- getLine
if (line == "") then
return ()
else
let i = (read line) in do
let (s', o) = f i s in do
- printOutput (
s', o
)
+ printOutput (
i, o, s'
)
simulateIO f s'
simulateIO f s'
-printOutput :: (Show s, Show o) => (s, o) -> IO ()
-printOutput (s, o) = do
- putStr "Output: "
+printOutput :: (Show i, Show o, Show s) => (i, o, s) -> IO ()
+printOutput (i, o, s) = do
+ putStr "Input: "
+ putStr $ show i
+ putStr "\nOutput: "
putStr $ show o
putStr "\nNew State: "
putStr $ show s
putStr $ show o
putStr "\nNew State: "
putStr $ show s