haskell-brainfuck-0.1.0.0: BrainFuck interpreter

Copyright(c) Sebastian Galkin, 2014
LicenseMIT
Maintainerparaseba@gmail.com
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

HaskBF.Tape

Description

Provides a type and operations to implement the brainfuck tape. The tape has the concept of a pointer, and the pointer can be incremented or decremented.

Synopsis

Documentation

data Tape t

Brainfuck tape. Constructor arguments correspond to - - 1. left of the current pointer - 2. current pointed value - 3. right of the current pointer - - The left part of the tape is reversed, so the first element of the list - is the rightmost position. The right list is normal order, its first element - is the leftmost one.

Constructors

Tape [t] t [t] 

Instances

Show t => Show (Tape t) 

data ExecutionError a

Type for execution errors, trying to move the tape beyond one of its - ends. The String argument is the error message and the Tape is in - the state right before the faulting operation

Instances

rTape

Arguments

:: Tape t

The tape

-> t

The element currently pointed by the pointer

Read the pointed element

wTape

Arguments

:: t

The element to write

-> Tape t

The tape

-> Tape t

The modified tape

Write element to the current position in the tape

inc

Arguments

:: Num a 
=> Tape a

The tape

-> Tape a

The tape with the current position incremented

Increment the currently pointed element

dec

Arguments

:: Num a 
=> Tape a

The tape

-> Tape a

The tape with the current position decremented

Decrement the currently pointed element

right

Arguments

:: Tape a

The tape

-> Either (ExecutionError a) (Tape a)

A new tape with its pointer pointing to the - element to the right of the pointer in the - original tape; or an execution error if the - tape to the right is exhausted

Move the pinter to the right

left

Arguments

:: Tape a

The tape

-> Either (ExecutionError a) (Tape a)

A new tape with its pointer pointing to - the element to the left of the pointer in - the original tape; or an execution error if - the tape to the left is exhausted

Move the pinter to the left

type BFExError = ExecutionError Int8

Execution error type for basic Brainfuck tapes

type BFTape = Tape Int8

Brainfuck tapes type

blankTape :: BFTape

A (0 :: Int8) initialized, infinite Tape pointing to its - leftmost position. An attemp to move the pointer left will result - in an error