A difference list is a function that, given a list, returns the original contents of the difference list prepended to the given list.
This structure supports O(1)
append
and concat
operations on lists, making it
useful for append-heavy uses such as logging and pretty printing.
Convert a list to a dlist
Equations
- dlist.of_list l = {apply := has_append.append l, invariant := _}
Create a dlist containing no elements
Create dlist with a single element
@[instance]
Equations
- dlist.has_append = {append := dlist.append α}
theorem
dlist.to_list_cons
{α : Type u}
(x : α)
(l : dlist α) :
(dlist.cons x l).to_list = x :: l.to_list
theorem
dlist.to_list_concat
{α : Type u}
(x : α)
(l : dlist α) :
(dlist.concat x l).to_list = l.to_list ++ [x]