feat: simproc for String.singleton (#12706)

This PR adds a dsimproc which evaluates `String.singleton ' '` to `" "`.
This commit is contained in:
Markus Himmel 2026-02-26 15:41:56 +01:00 committed by GitHub
parent b3b4867d6c
commit a91fb93eee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -46,6 +46,11 @@ builtin_dsimproc [simp, seval] reducePush (String.push _ _) := fun e => do
let some m ← Char.fromExpr? e.appArg! | return .continue let some m ← Char.fromExpr? e.appArg! | return .continue
return .done <| toExpr (n.push m) 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 @[inline] def reduceBinPred (declName : Name) (arity : Nat) (op : String → String → Bool) (e : Expr) : SimpM Step := do
unless e.isAppOfArity declName arity do return .continue unless e.isAppOfArity declName arity do return .continue
let some n ← fromExpr? e.appFn!.appArg! | return .continue let some n ← fromExpr? e.appFn!.appArg! | return .continue

View file

@ -50,5 +50,10 @@ example : "b" > "a" := by simp
example : "abc" ≥ "abc" := by simp example : "abc" ≥ "abc" := by simp
example : "abd" ≥ "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 -- Combined: roundtrip toList/ofList
example : String.ofList "hello".toList = "hello" := by simp example : String.ofList "hello".toList = "hello" := by simp