esolang

Trivial

Haskell with everything taken out. No types, no numbers, no builtins, only functions.

Hakerh400, 2021 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: hi

The idea

Hakerh400 made Trivial in 2021 on the Hot calculus, and each Trivial program compiles to one Hot combinator. A program is a list of global functions, name args = body;. Nothing is built in. Bits, pairs, lists and integers all have to be written as functions, and the only way to look at a value is to call it. A name may hold any character but whitespace, parentheses and ;, so +, ==, [] and cmp{int}' are ordinary functions.

Read the story

The specification gives one large example of 172 definitions. It builds bits, pairs, Maybe, lists with map and the folds, and integers as lists of bits with add, multiply and divide. Then it reads numbers and prints the sum of the odd ones. That takes 2,251,897 reductions.

The machine

The first function is the main one. It gets io and is reduced lazily, with arguments shared.

CodeDoes
B0 a b = b; B1 a b = a;A bit is a function that keeps one of two arguments
io B0 kRead a bit and go on with k bit
io B1 b kWrite the bit b and go on with k

Bits travel in pairs, a 1 and then the bit, and a 0 ends the stream. As text, each byte is 8 bits, lowest first. Writing the closing 0 ends the run. The specification leaves the I/O to the Hot calculus, and this implementation takes it from the specification's own program.

Example

The cat reads a flag, and while it is 1 reads a bit and writes a 1 and the bit.

The cat reads a flag, and while it is 1 reads a bit and writes a 1 and the bit.

The letter A is 65, which is 1 0 0 0 0 0 1 0 from the lowest bit, each written after a 1.

Expected: A

The program, given 0 1 10 6 67 5 5 97 559 911 44 8 696 8 5 763 8 590 100, prints 2413.

Patterns it teaches

  • Combinators: every function is a combinator; K and S take a line each.
  • Lambda encoding: bits, pairs, lists and integers made of functions.

Further

Functional paradigm

Write your own in Run Convert a program from Trivial

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: trivial.

Command line

shib run trivial program.txt --input '0 1 10 6 67 5 5 97 559 911 44 8 696 8 5 763 8 590 100'

The program is long; save it as program.txt first.

shib manual trivial

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/trivial.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org