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