Proposal: lawful lenses for verified state access
维护者通常 1 天内回复
@Digger-Rockwell 已经在做这个了。
开始于 2026年11月18日。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 领域
- tooling
调研方向
首先阅读 docs/upstream/CSLIB_LENS_PROPOSAL.md 以及 lean-optics 中的 Optics.Examples.MachineState 示例,然后比较提议放置在 Cslib/Foundations/Data/Lens/ 下的方案。完整的贡献需要维护者就命名和组合范围达成一致,随后实现最小的 lens API,并提供一个包含其所述定律的自包含 MachineState 示例。
由索引模型根据 Issue 内容生成。
描述
Problem
Verified computer-science developments often need structured state updates over records. When modeling interpreters, simulators, or incremental transformations, authors repeatedly write the same pattern: read a field from a state record, compute an updated value, and write it back while preserving unrelated fields. Without a shared abstraction, each project reimplements getters, setters, and the algebraic laws that make those updates composable and trustworthy.
Proposed minimal API
A small lawful lens core for verified state access (not category theory or profunctor optics):
structure Lens (S A : Type u) where
get : S → A
set : S → A → S
structure LawfulLens (S A : Type u) extends Lens S A where
get_set : ∀ s a, get (set s a) = a
set_get : ∀ s, set s (get s) = s
set_set : ∀ s a b, set (set s a) b = set s b
Plus:
over— update the focused component with a functioncompose— chain nested field access
Example: interpreter state
structure MachineState where
pc : Nat
memory : List Nat
halted : Bool
A lawful lens for pc, a step function that increments pc when not halted, and proofs that step preserves memory and halted.
This pattern is exercised in lean-optics (Optics.Examples.MachineState) as an extraction candidate; see also docs/upstream/CSLIB_LENS_PROPOSAL.md in that repo.
Why CSLib
CSLib is the right venue for executable state semantics and verified transformations without tactic automation. The API should be small enough to review in one sitting and strong enough to support verified record updates in algorithms, semantics, and systems formalizations.
Explicitly out of scope (for this first PR)
- Profunctor hierarchy and optic generalizations
- Prisms, traversals, and other optic variants
- Macros (
lens!, field-syntax sugar) optic_laws!and other tactic automation- Telemetry and benchmarks
Suggested placement
Cslib/Foundations/Data/Lens/ (or similar under Foundations), with one self-contained example module.
Mathlib
Not proposed for this slice. Mathlib optimizes for mathematical structure; the immediate need is a tiny, law-carrying API for executable state in CS developments.
Next step
Happy to open a draft PR with only the minimal API + MachineState example if maintainers agree with the framing. Feedback welcome on naming, placement, and whether composition laws should ship in v1.
- 主要语言
- Lean
- 星标
- 847
- 派生
- 234
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 49
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
leanprover/cslib 的其他 Issue
-
`listFullBeta_cons_r` should rename to `listFullBeta_concat_r`可能已有人在做 @lengyijun 于 134 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
leanprover/cslib#784 ·
维护者通常 1 天内回复
-
logic
难度 1/5 1 小时以内 新手友好度 72/100
leanprover/cslib#74 ·
维护者通常 1 天内回复
-
dependency-incompatibility
难度 3/5 半天 新手友好度 45/100
leanprover/cslib#1271 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
leanprover/cslib#1262 ·
维护者通常 1 天内回复
-
BetaAt.appR doesn't require LC N, weakening BetaAt.lc_r, not consistent with FullBeta可能已有人在做 @Digger-Rockwell 于 5 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
leanprover/cslib#1243 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
erkamyaman/rust-anything#364 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
erkamyaman/safe-anything#47 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
generative-computing/mellea#1864 ·
维护者通常 3 天内回复
-
documentation good first issue
难度 2/5 半天 新手友好度 66/100
-
难度 2/5 1-3 小时 新手友好度 82/100
ubugeeei-prod/vize#13586 ·
维护者通常 1 天内回复