feat: simproc for String.singleton (#12706)
This PR adds a dsimproc which evaluates `String.singleton ' '` to `" "`.
This commit is contained in:
parent
b3b4867d6c
commit
a91fb93eee
2 changed files with 10 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue