Proposal: lawful lenses for verified state access

Đang mở
#658 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Digger-Rockwell đang làm issue này rồi.

Từ ngày 18/11/2026.

  • #4 của @Digger-Rockwell — đang mở
  • #1248 của @Digger-Rockwell — đang mở

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách đọc docs/upstream/CSLIB_LENS_PROPOSAL.md và ví dụ Optics.Examples.MachineState trong lean-optics, sau đó so sánh vị trí được đề xuất dưới Cslib/Foundations/Data/Lens/. Một đóng góp hoàn chỉnh sẽ cần sự thống nhất của maintainer về cách đặt tên và phạm vi composition, tiếp theo là lens API tối thiểu và một ví dụ MachineState độc lập với các luật được nêu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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 function
  • compose — 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.

Ngôn ngữ chính
Lean
Star
847
Fork
234
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
49

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của leanprover/cslib

Tất cả issue của leanprover/cslib

Issue tương tự

Thêm issue về DevTools

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.