-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A simple simulator for Turing machines -- -- This package provides some basic functions and types to simulate a -- Turing machine. @package turing @version 0.1.0 -- | This module defines everything required to simulate a simple -- deterministic Turing machine. There are several equivalent but -- slightly different definitions of Turing machines in use - ours has -- the machine write and move in each step of execution. In -- addition, we allow a special movement DontMove that results in -- just a write operation. module Data.Turing -- | Abstract type representing a Turing machine. It is parameterized over -- the alphabet and state types. A full definition contains the initial -- state, a list of accepting states and the transition function. -- Construct through mkTuringMachine. data TuringMachine s q -- | Construct a Turing machine from the transition function, its initial -- state and a list of accepting states. mkTuringMachine :: TransitionFunction s q -> q -> [q] -> TuringMachine s q -- | A Turing machine has three options of moving its read head: left, -- right, or no move at all. data Movement MoveLeft :: Movement MoveRight :: Movement DontMove :: Movement -- | The transition function maps the current state and tape contents to a -- triple describing the new state, the value to write to the tape, and a -- head movement. If the function is Nothing for the current state -- and tape contents, the machine halts. type TransitionFunction s q = (q, Maybe s) -> Maybe (q, Maybe s, Movement) -- | A machine can either accept or reject the input (for now). data MachineResult Accept :: MachineResult Reject :: MachineResult -- | Run a machine indefinitely on the given input. If it halts, it either -- accepts or rejects the input. run :: Eq q => TuringMachine s q -> [s] -> MachineResult -- | Run a machine for the given number of steps. If this is enough for it -- to halt, the result is the same as for run, wrapped in -- Just; otherwise it is Nothing. runFor :: (Integral i, Eq q) => i -> TuringMachine s q -> [s] -> Maybe MachineResult instance GHC.Show.Show Data.Turing.MachineResult instance GHC.Classes.Eq Data.Turing.MachineResult instance GHC.Show.Show Data.Turing.Movement instance GHC.Classes.Eq Data.Turing.Movement