Skip to content

Commit

Permalink
refactor(init/data/string/*): implement decidable equality for string…
Browse files Browse the repository at this point in the history
…s without using tactics (#204)
  • Loading branch information
JLimperg committed Apr 28, 2020
1 parent 2259a2c commit f1fc405
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library/init/data/list/instances.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Leonardo de Moura
-/
prelude
import init.data.list.lemmas
import init.meta.mk_dec_eq_instance init.control.lawful

open list

universes u v
Expand Down
7 changes: 7 additions & 0 deletions library/init/data/string/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ def list.as_string (s : list char) : string :=
⟨s⟩

namespace string

instance : has_lt string :=
⟨λ s₁ s₂, s₁.data < s₂.data⟩

/- Remark: this function has a VM builtin efficient implementation. -/
instance has_decidable_lt (s₁ s₂ : string) : decidable (s₁ < s₂) :=
list.has_decidable_lt s₁.data s₂.data

instance has_decidable_eq : decidable_eq string := λ ⟨x⟩ ⟨y⟩,
match list.has_dec_eq x y with
| is_true p := is_true (congr_arg string_imp.mk p)
| is_false p := is_false (λ q, p (string_imp.mk.inj q))
end

def empty : string :=
⟨[]⟩

Expand Down
2 changes: 1 addition & 1 deletion library/init/data/string/default.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.string.basic init.data.string.instances init.data.string.ops
import init.data.string.basic init.data.string.ops
10 changes: 0 additions & 10 deletions library/init/data/string/instances.lean

This file was deleted.

3 changes: 1 addition & 2 deletions library/init/meta/name.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def name.update_prefix : name → name → name
| (mk_string s p) new_p := mk_string s new_p
| (mk_numeral s p) new_p := mk_numeral s new_p

/- The (decidable_eq string) has not been defined yet.
So, we disable the use of if-then-else when compiling the following definitions. -/
-- Without this option, we get errors when defining the following definitions.
set_option eqn_compiler.ite false

def name.to_string_with_sep (sep : string) : name → string
Expand Down
2 changes: 1 addition & 1 deletion library/init/meta/well_founded_tactics.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Authors: Leonardo de Moura
-/
prelude
import init.meta init.data.sigma.lex init.data.nat.lemmas init.data.list.instances
import init.data.list.qsort init.data.string.instances
import init.data.list.qsort

/- TODO(Leo): move this lemma, or delete it after we add algebraic normalizer. -/
lemma nat.lt_add_of_zero_lt_left (a b : nat) (h : 0 < b) : a < a + b :=
Expand Down

0 comments on commit f1fc405

Please sign in to comment.