mirror of
https://github.com/leanprover/lean4.git
synced 2026-03-17 18:34:06 +00:00
feat: simproc for String.singleton (#12706)
This PR adds a dsimproc which evaluates `String.singleton ' '` to `" "`.
This commit is contained in:
@@ -46,6 +46,11 @@ builtin_dsimproc [simp, seval] reducePush (String.push _ _) := fun e => do
|
||||
let some m ← Char.fromExpr? e.appArg! | return .continue
|
||||
return .done <| toExpr (n.push m)
|
||||
|
||||
builtin_dsimproc [simp, seval] reduceSingleton (String.singleton _) := fun e => do
|
||||
unless e.isAppOfArity ``String.singleton 1 do return .continue
|
||||
let some c ← Char.fromExpr? e.appArg! | return .continue
|
||||
return .done <| toExpr (String.singleton c)
|
||||
|
||||
@[inline] def reduceBinPred (declName : Name) (arity : Nat) (op : String → String → Bool) (e : Expr) : SimpM Step := do
|
||||
unless e.isAppOfArity declName arity do return .continue
|
||||
let some n ← fromExpr? e.appFn!.appArg! | return .continue
|
||||
|
||||
@@ -50,5 +50,10 @@ example : "b" > "a" := by simp
|
||||
example : "abc" ≥ "abc" := by simp
|
||||
example : "abd" ≥ "abc" := by simp
|
||||
|
||||
-- String.reduceSingleton
|
||||
example : String.singleton ' ' = " " := by simp
|
||||
example : String.singleton 'a' = "a" := by simp
|
||||
example : String.singleton '\n' = "\n" := by simp
|
||||
|
||||
-- Combined: roundtrip toList/ofList
|
||||
example : String.ofList "hello".toList = "hello" := by simp
|
||||
|
||||
Reference in New Issue
Block a user