diff options
-rw-r--r-- | IterableClass.dcl | 10 | ||||
-rw-r--r-- | IterableClass.icl | 6 | ||||
-rw-r--r-- | TuringMachines.icl | 6 |
3 files changed, 13 insertions, 9 deletions
diff --git a/IterableClass.dcl b/IterableClass.dcl index 729cd68..73c9776 100644 --- a/IterableClass.dcl +++ b/IterableClass.dcl @@ -1,10 +1,10 @@ definition module IterableClass -class step a :: a -> a -class rewind a :: a -> a +class step a :: !a -> a +class rewind a :: !a -> a -stepn :: Int a -> a | step a -rewindn :: Int a -> a | rewind a +stepn :: Int !a -> a | step a +rewindn :: Int !a -> a | rewind a -stepOrRewindn :: Int a -> a | step, rewind a +stepOrRewindn :: Int !a -> a | step, rewind a diff --git a/IterableClass.icl b/IterableClass.icl index 97340ba..0aa2dda 100644 --- a/IterableClass.icl +++ b/IterableClass.icl @@ -2,15 +2,15 @@ implementation module IterableClass import StdEnv -stepn :: Int a -> a | step a +stepn :: Int !a -> a | step a stepn 0 a = a stepn n a = stepn (n-1) (step a) -rewindn :: Int a -> a | rewind a +rewindn :: Int !a -> a | rewind a rewindn 0 a = a rewindn n a = rewindn (n-1) (rewind a) -stepOrRewindn :: Int a -> a | step, rewind a +stepOrRewindn :: Int !a -> a | step, rewind a stepOrRewindn 0 a = a stepOrRewindn n a | n < 0 = rewindn (0-n) a diff --git a/TuringMachines.icl b/TuringMachines.icl index b37233c..f13ca7d 100644 --- a/TuringMachines.icl +++ b/TuringMachines.icl @@ -30,7 +30,10 @@ where instance toString (TuringMachineState a) | toString a where toString st=:{state,tapeHead,tape,running} - = toString running +++ " turing machine in state " +++ toString state +++ ", tape head at " +++ toString tapeHead +++ ".\nTape: " +++ toString tape + = toString (take tapeHead tape) +++ + "[q" +++ toString state +++ "]" +++ + toString (drop tapeHead tape) +++ + " (" +++ toString running +++ ")" instance == Direction where @@ -55,6 +58,7 @@ instance step (TuringMachineState a) | == a where step st=:{machine,state,tapeHead,tape,running} | running <> Running = st + # tape = if (length tape < tapeHead + 1) (tape ++ [Nothing]) tape # move = machine.transition state (tape!!tapeHead) | move == Halt = {st & running = Normal} # (Step state write dir) = move |