StackTape: Infinite, eventually-none lists of Options #
This file defines StackTape, a stack-like data structure of Option values,
where the tape is considered to be infinite and eventually all nones.
This is useful as a data structure with a simple API for manipulation by Turing machines.
Design #
StackTape is represented as a list of Option values where the list cannot end with none.
The end of the list is then treated as the start of an infinite sequence of none values
by the low-level API.
This design makes it convenient to express the length of the tape in terms of the list length.
An alternative design would be to represent the tape as a Stream' (Option Symbol),
with additional fields tracking the length and the fact that the stream eventually becomes none.
This design might complicate reasoning about the length of the tape, but could make other operations
more straightforward.
Future design work might explore this alternative representation and compare its advantages and disadvantages.
TODO #
- Make a
::-like notation.
An infinite tape representation using a list of Option values,
where the list is eventually none.
Represented as a List (Option Symbol) that does not end with none.
The underlying list representation
The list can be empty (i.e.
none), but if it is not empty, the last element is not (some)none
Instances For
Equations
- Turing.StackTape.instInhabited = { default := Turing.StackTape.nil }
Equations
- Turing.StackTape.instEmptyCollection = { emptyCollection := Turing.StackTape.nil }
Prepend an Option to the StackTape
Equations
- Turing.StackTape.cons none { toList := [], toList_getLast?_ne_some_none := toList_getLast?_ne_some_none } = { toList := [], toList_getLast?_ne_some_none := ⋯ }
- Turing.StackTape.cons none { toList := hd :: tl, toList_getLast?_ne_some_none := hl } = { toList := none :: hd :: tl, toList_getLast?_ne_some_none := ⋯ }
- Turing.StackTape.cons (some a) { toList := l, toList_getLast?_ne_some_none := hl } = { toList := some a :: l, toList_getLast?_ne_some_none := ⋯ }