A stateful query type for Singly Linked Lists #
The query type SinglyLinkedList α models the abstract interface
for a singly linked list. Its basic interface is identical
to that of it's functional programming cousin, a recursively defined
list.
A state type with a single list that is used to internally represent linear data structures like linked lists, stacks, and queues.
- internalList : List α
The internal list
Instances For
An ADT query type for a stack. Note this is essentially identical to the List query type, but with renamed queries to match the typical names of a stack interface.
- peek {s : Strategy} {α : Type u} : ListADT s α (Option α)
- drop {s : Strategy} {α : Type u} : ListADT s α PUnit.{u + 1}
- insert {s : Strategy} {α : Type u} (data : α) : ListADT s α PUnit.{u + 1}
Instances For
@[simp]
theorem
Algolean.Algorithms.listModel_evalQuery
{α : Type}
(s : Strategy)
{α✝ : Type}
(x✝ : ListADT s α α✝)
:
(listModel s).evalQuery x✝ = match α✝, x✝ with
| .(Option α), ListADT.peek => do
let iL ← get
pure iL.internalList.head?
| .(PUnit.{1}), ListADT.drop => do
let iL ← get
set { internalList := iL.internalList.tail }
pure ()
| .(PUnit.{1}), ListADT.insert x =>
match s with
| Strategy.lifo => modify fun (iL : ListState α) => { internalList := x :: iL.internalList }
| Strategy.fifo => modify fun (iL : ListState α) => { internalList := iL.internalList ++ [x] }
@[reducible, inline]
Interpretation of ListADT as the ADT of a stack
Equations
Instances For
@[reducible, inline]
Interpretation of ListADT as the ADT of a queue