Stack-oriented toy language with static types and type inference
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


CoinScript is a toy programming language for experimenting with stack-oriented programming, type inference and termination analysis. Bitcoin's scripting language pointed out that I know little about stack-oriented programming. This is me learning. As a hat tip, and since I'm bad at naming, it's called CoinScript.

A CoinScript program is a string of Unicode characters. Like FALSE and F ("Functional False"), each character in the script is a stack operation. The script 40 2+ adds the numbers 40 and 2, leaving 42 on the stack as the program's output.

So far, CoinScript's only unique feature (as far as I can tell), is the type inference mechanism. All language operations are defined in terms of a generic virtual machine interface. Running a program on the "data machine" produces its output. Running a program on the "type machine" produces its type signature.

The first implementation was 116 lines of Haskell. That seems pretty decent for a language interpreter and type inference engine.

Data Types

Boolean: the operations t and f push a true or false value onto the stack, respectively.

Integers: an integer literal like 1234 is pushed onto the stack as is. To push consecutive numbers, separate them with a space: 1 2.

Strings: a string literal is enclosed in double quotes, "like this".

Lists: a list starts with ( and ends with ). Values inside the list are separated with ,. For non-empty lists, a trailing , is required. For example, (1,2,4 1+,) pushes a list onto the stack containing 1, 2 and 5. This works because ( pushes an empty list onto the stack and , appends items onto it. The same result could be accomplished with ()1,2,4 1+,. All values in a list should be of the same type.

Code: a code literal is bracketed by [ and ]. The operations inside are not executed. For example, [1 2+] pushes a code value onto the stack containing 1 2+, not the integer 3. To execute a code value, use !.

Stack Operations

  • + - numeric addition
  • d - dup
  • D - drop
  • ( - push an empty list
  • , - append an item to a list
  • ) - noop (required for balancing ()
  • ! - execute code literal on top of the stack
  • space - noop (useful for separating consecutive integers)