leanprover / leanprover/lean4

RFC: `open` keyword in `do`-monad

Open
#6,884 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

do-notation P-low RFC
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Proposal

I would like to see the following code work:

namespace Foo
def ara: String := "ara"
end Foo

def yolo: IO Unit := do
  open Foo
  IO.print s!"{ara}"

#eval yolo

in other words, it should be syntactically-valid in Lean to write open <namespace> in a do-monad, and have that namespace be opened for the rest of the lines in that do block.

I think it makes sense for the syntax to be open <namespace> and not open <namespace> in, but I don't feel strongly about the presence/absence of in.

Currently, the compiler error message for this case is rather confusing, so making it be legal syntax would eliminate a confusing compiler error message and make it somewhat more convenient to use a do-monad

Community Feedback

https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/.60open.60.20in.20.60do.60.20blocks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The proposal concerns Lean do-monad syntax and the compiler error produced for open Foo inside a do block, but it names no files, tests, or entry points. Start by tracing parsing and elaboration for do blocks, then review the linked Zulip discussion before deciding between the proposed syntax forms. Done means the example is syntactically valid and the namespace remains open for the rest of the block.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.