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
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
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

View File

@@ -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