A State Monad Tutorial
Code that is intended to be typed in a ghci session or output from ghci is contained in a
green background.
Code that is intended to be loaded from a source file by ghci or other Haskell code is contained in a
Monads tend to be a difficult concept for beginners to understand. In this guide, I try a different approach by explaining non-monadic values and building from there. If you want to understand monads, please don’t breeze through this tutorial, as you will need to think to understand them.
I will first explain the State type. Let us import it and look at its type: Read the rest of this entry »
cfopu, a minimalistic esoteric language similar to brainfuck and Assembly language
cfopu is a primitive, minimalistic language, similar to assembly and brainfuck. It can read input from stdin, and print to stdout. When a file is interpreted, its contents are placed in memory after being processed by the preprocessor.
There are two pointers: the data pointer, and the instruction pointer, both of which initially point to the first byte. Each byte is parsed, the instruction pointer is set ahead by one byte, and then the command is executed if the byte is a command. There are only 8 primitive commands:
0: End the program.
1: Print current byte.
2: Get one character (blocking, if necessary). If EOF has been reached, the data pointer is set behind by one.
3: Set the data pointer behind by one.
4: Set the data pointer ahead by two.
5: Decrement the value pointed to by the data pointer by one.
6: If the current byte is non-zero, the data pointer is set behind by one; otherwise, the data pointer is set forward by two.
7: Sets the instruction pointer to the data pointer.