Get the full source, or continue reading for a better understanding of it.
The source below is slightly changed for formatting reasons.
General imports and the two main data structures, a state monad transformer over IO, and the state
type, which holds the program counter, a pointer, the memory as a mutable array and the program code
as an immutable array.
The main function reads a file (if given on cmdline) and passes it on to runBF. runBF allocates
an array of 30 000 and runs the program in that array. Note that 30 000 is a sort of arbitrary
number, and since Brainfuck essentially models a Turing
machine, the tape is in theory infinite.
Well, evalBF is a fetch-execute loop. There are 8 different commands available. The @ command is
not as standard as the rest, but it is common for Brainfuck interpreters to see it as an exit
command. See below for the functions that are called above.