brainfuck-tut: A simple BF interpreter.

[ bsd3, language, library, program ] [ Propose Tags ]

[Skip to Readme]
Versions [faq],,,,,,,,
Change log
Dependencies array, base (==4.7.*), brainfuck-tut [details]
License BSD-3-Clause
Copyright (c) 2014 Alejandro Cabrera
Author Alejandro Cabrera
Category Language
Home page
Bug tracker
Source repo head: git clone git clone
Uploaded by alcabrera at Sun Nov 23 05:41:55 UTC 2014
Distributions NixOS:
Executables bfh
Downloads 3753 total (89 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]




Maintainer's Corner

For package maintainers and hackage trustees

Readme for brainfuck-tut-

[back to package description]

Brainfuck: A Toy Implementation

This project exists to show what a Brainfuck evaluator might look like in Haskell.

The implementation is fairly well documented. I endeavored to make it readable.


Below is the abstract syntax tree for the BF language as implemented:

data Term
  = IncDP        -- >
  | DecDP        -- <
  | IncByte      -- +
  | DecByte      -- -
  | OutByte      -- .
  | InByte       -- ,
  | JumpForward  -- [
  | JumpBackward -- ]
  deriving (Show, Eq)

Evaluation Semantics

I followed the summary given on the wikipedia page closely. A few particulars to this implementation:

  • "Jump not found" errors abort evaluation and return the state of the tape
  • Out of bound errors are not detected
  • Evaluation proceeds until the instruction stream runs out


An executable is provided:

$ cabal build bfh
$ cabal run bfh
usage: bfh <size> <program>
$ cabal run bfh 10 ',.'