brainfuck-monad-0.1.0: BrainFuck monad

Safe HaskellSafe-Inferred
LanguageHaskell98

Control.Monad.BrainFuck

Synopsis

Documentation

newtype BrainFuck a Source

Constructors

BrainFuck (DataPointer -> ([Char], DataPointer, a)) 

Instances

func :: BrainFuck f -> DataPointer -> ([Char], DataPointer, f) Source

Retrieve the inner function

brainfuck :: BrainFuck f -> String Source

Evaluate the monad and get a brainfuck program

next :: BrainFuck () Source

move data pointer right

close :: BrainFuck () Source

if byte at data pointer is nonzero, jump to command after matching open

open :: BrainFuck () Source

if byte at data pointer is zero, jump to command after close

input :: BrainFuck () Source

input byte, storing at data pointer

output :: BrainFuck () Source

output byte at data pointer

decr :: BrainFuck () Source

decrement data

incr :: BrainFuck () Source

increment data

prev :: BrainFuck () Source

move data pointer left

opcode :: Char -> BrainFuck () Source

Adds an arbitrary character to the program. Should not be used directly.

opcode' :: (DataPointer -> DataPointer) -> Char -> BrainFuck () Source

Adds an arbitrary character to the program, and updates the data pointer. Should not be used directly.

multi :: BrainFuck () -> Int -> BrainFuck () Source

Run an action multiple times.

char :: Char -> BrainFuck () Source

Assuming that the data pointer points to a 0, changes it to the value of a Char.

withChar :: Char -> BrainFuck a -> BrainFuck a Source

Runs an action with the data pointer pointing at a Char.

addr :: BrainFuck DataPointer Source

Gets the current address of the data pointer.

setAddr :: Integer -> BrainFuck () Source

Moves the data pointer to a specific address.

loopUnless0 :: BrainFuck () -> BrainFuck () Source

The loop is only run if the data pointer doesn't point to 0.

On entry, the loop body is run, and then it loops, until the data pointer points to 0.

brainfuckConstants :: NumConstants -> (Constants -> BrainFuck a) -> String Source

Let's run programs with data addresses 0..n reserved to always contain the numbers n..0

These constants will make brainfuck quite a bit easier to use!

pointAt :: Constants -> Integer -> BrainFuck () Source

Sets data pointer to point to one of the Constants.

loop :: Constants -> BrainFuck () -> BrainFuck () Source

Run an action in a loop, until the data pointer points to 0.

forever :: Constants -> BrainFuck () -> BrainFuck () Source

Runs an action in an infinite loop.

demo :: String Source

Prints out the ASCII characters, starting with space, repeatedly.

TODO: Only print printable characters.