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.
Instances for dlist
- dlist.has_sizeof_inst
- dlist.has_append
- dlist.traversable
- dlist.is_lawful_traversable
- dlist.inhabited
Convert a list to a dlist
Equations
- dlist.of_list l = {apply := has_append.append l, invariant := _}
Convert a lazily-evaluated list to a dlist
Equations
- dlist.lazy_of_list l = {apply := λ (xs : list α), l unit.star() ++ xs, invariant := _}
Create dlist with a single element
@[protected, 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