From 281425310c5db21f87981eeb9601a71d1974d98d Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 10 Apr 2014 05:25:03 +1000 Subject: Rearranging files --- src/Brainfuck/Tape.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Brainfuck/Tape.hs (limited to 'src/Brainfuck/Tape.hs') diff --git a/src/Brainfuck/Tape.hs b/src/Brainfuck/Tape.hs new file mode 100644 index 0000000..8da4352 --- /dev/null +++ b/src/Brainfuck/Tape.hs @@ -0,0 +1,46 @@ +module Brainfuck.Tape ( + Tape, + + shiftLeft, + shiftRight, + currentCell, + applyToCurrentCell + ) where + + +import Control.Monad +import Data.Maybe + + + +type Tape a = ([a], Maybe a, [a]) + + + + +shiftLeft :: Eq a => Tape a -> Tape a +shiftLeft (x,y,z) = + let x' = if (x /= []) then tail x else x + y' = if (x /= []) then Just (head x) else Nothing + z' = if (isJust y) then (fromJust y):z else z + in (x', y', z') + + + +shiftRight :: Eq a => Tape a -> Tape a +shiftRight (x,y,z) = + let x' = if (isJust y) then (fromJust y):x else x + y' = if (z /= []) then Just (head z) else Nothing + z' = if (z /= []) then tail z else z + in (x', y', z') + + + +currentCell :: Tape a -> Maybe a +currentCell (_,c,_) = c + + + +applyToCurrentCell :: (a -> a) -> Tape a -> Tape a +applyToCurrentCell f (x,y,z) = (x, (liftM f) y, z) + -- cgit