In the VM, strings are implemented using a dynamic array and UTF-8 encoding.
TODO: we currently cannot mark string_imp as private because we need to bind string_imp.mk and string_imp.cases_on in the VM.
Instances for string_imp
- string_imp.has_sizeof_inst
- string_imp.inhabited
Equations
Remark: this function has a VM builtin efficient implementation.
Equations
- s₁.has_decidable_lt s₂ = s₁.data.has_decidable_lt s₂.data
Equations
- string.has_decidable_eq = λ (_x : string), string.has_decidable_eq._match_3 _x
- string.has_decidable_eq._match_3 {data := x} = λ (_x : string), string.has_decidable_eq._match_2 x _x
- string.has_decidable_eq._match_2 x {data := y} = string.has_decidable_eq._match_1 x y (list.has_dec_eq x y)
- string.has_decidable_eq._match_1 x y (decidable.is_true p) = decidable.is_true _
- string.has_decidable_eq._match_1 x y (decidable.is_false p) = decidable.is_false _
O(n) in the VM, where n is the length of the string
Equations
- string.to_list {data := s} = s
Equations
- string.fold a f s = list.foldl f a s.to_list
In the VM, the string iterator is implemented as a pointer to the string being iterated + index.
TODO: we currently cannot mark interator_imp as private because we need to bind string_imp.mk and string_imp.cases_on in the VM.
Instances for string.iterator_imp
- string.iterator_imp.has_sizeof_inst
- string.iterator_imp.inhabited
Equations
Instances for string.iterator
Equations
- string.iterator.curr {fst := p, snd := c :: n} = c
- string.iterator.curr {fst := fst, snd := list.nil char} = inhabited.default
In the VM, set_curr
is constant time if the string being iterated is not shared and linear time
if it is.
In the VM, to_string
is a constant time operation.
Equations
- string.iterator.extract_core (c :: cs₁) cs₂ = ite (cs₁ = cs₂) (option.some [c]) (string.iterator.extract_core._match_1 c (string.iterator.extract_core cs₁ cs₂))
- string.iterator.extract_core list.nil cs = option.none
- string.iterator.extract_core._match_1 c (option.some r) = option.some (c :: r)
- string.iterator.extract_core._match_1 c option.none = option.none
Equations
- string.iterator.extract {fst := p₁, snd := n₁} {fst := p₂, snd := n₂} = ite (p₁.reverse ++ n₁ ≠ p₂.reverse ++ n₂) option.none (ite (n₁ = n₂) (option.some "") (string.iterator.extract._match_1 (string.iterator.extract_core n₁ n₂)))
- string.iterator.extract._match_1 (option.some r) = option.some {data := r}
- string.iterator.extract._match_1 option.none = option.none
The following definitions do not have builtin support in the VM
Equations
- string.inhabited = {default := ""}
Equations
Equations
Equations
- s.is_empty = decidable.to_bool (s.length = 0)
Equations
- string.join l = list.foldl (λ (r s : string), r ++ s) "" l
Equations
- s.intercalate ss = (s.to_list.intercalate (list.map string.to_list ss)).as_string
Equations
Equations
- s.popn_back n = (s.mk_iterator.to_end.prevn n).prev_to_string
Equations
- s.backn n = (s.mk_iterator.to_end.prevn n).next_to_string