blob: 273c70baa1ccc72aee0ec3acbc788614eef87b55 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
module turinglog
import StdEnv
import TuringMachines
Start :: *World -> *World
Start w
# (io,w) = stdio w
# m = initTuringMachine machine tape
# io = fwrites (toString m +++ "\n") io
# io = loop m io
# (ok,w) = fclose io w
| not ok = abort "Couldn't close stdio\n"
| otherwise = w
where
loop m f
# m = step m
# f = fwrites (toString m +++ "\n") f
| m.running == Running = loop m f
| otherwise = f
tape :: Tape Char
tape = [Just c \\ c <- fromString "abbaba"]
machine :: TuringMachine Char
machine = { alphabet = ['a', 'b'],
inputs = ['a', 'b'],
transition = f }
where
f :: Int (Maybe Char) -> TuringMachineMove Char
f 0 Nothing = Step 1 Nothing Right
f 1 Nothing = Step 2 Nothing Left
f 1 (Just 'a') = Step 1 (Just 'b') Right
f 1 (Just 'b') = Step 1 (Just 'a') Right
f 2 (Just 'a') = Step 2 (Just 'a') Left
f 2 (Just 'b') = Step 2 (Just 'b') Left
f _ _ = Halt
|