Copyright | (C) 2016 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Computationally universal register machine implementation at the type-level.
This formulation is identical to the Lambek
machine, with the addition
of an explicit Halt
instruction, for convenience.
This means (or rather, this is made possible by the fact) that that Haskell's type system is Turing complete (at least with TypeFamilies and UndecidableInstances).
Construct and run the machine
type family Run is :: Machine Source
Run a list of instructions (Instr
)
If the program terminates, the result is a Halted
machine.
(See the Halting problem)
Otherwise the execution hangs the type-checker and eventually consumes all the available RAM.
Run is = Execute (Init is) |
Instructions
The GADT representing the intructions
The following 3 instructions are supported:
Inc r l
- increments register r
by 1, and then jumps to label l
(that is the instruction located at index l
).
Dec r l1 l2
- if the value of register r
is 0, jumps to l2
, otherwise
decrements r
and jumps to l1
.
Halt
- halts the machine.
The Ptr
arguments are specifying the register.
Some examples
Inc (R 1) (L 1) Dec (R 1) (L 7) (L 12) Halt