Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make it possible to use dot notation in m! strings #5857

Merged
merged 3 commits into from
Oct 27, 2024

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Oct 27, 2024

This default instance makes it possible to write things like m!"the constant is {.ofConstName n}".

Breaking change: This weakly causes terms to have a type of MessageData if their type is otherwise unknown. For example:

  • m!"... {x} ..." can cause x to have type MessageData, causing the let definition of x to fail to elaborate. Fix: give x an explicit type.
  • Arithmetic expressions in m! strings may need a type ascription. For example, if the type of i is unknown at the time the arithmetic expression is elaborated, then m!"... {i + 1} ..." can fail saying that it cannot find an HAdd Nat Nat MessageData instance. Two fixes: either ensure that the type of i is known, or add a type ascription to guide the MessageData coercion, like m!"... {(i + 1 : Nat)} ...".

kmill added 2 commits October 26, 2024 18:40
This default instance makes it possible to write things like `m!"the constant is {.ofConstName n}"`.
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Oct 27, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 27, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 27, 2024
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Oct 27, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Oct 27, 2024

Mathlib CI status (docs):

@nomeata
Copy link
Collaborator

nomeata commented Oct 27, 2024

Breaking change: arithmetic expressions in m! strings may need a type ascription, for example m!"... {i + 1} ..." -> m!"... {(i + 1 : Nat)} ...".

Is that only when the type of i is otherwise unknown, or now always? Does it affect plain m!"{i}"?

(Maybe include the answers in the description so that they make it to the release notes.)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 27, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 27, 2024
@kmill
Copy link
Collaborator Author

kmill commented Oct 27, 2024

@nomeata It affects {i} too when the type of i is unknown, but only if it's still unknown by the time default instances apply. The mathlib breakage so far has been a case where the default instance chose to apply, causing i to become MessageData, causing the let binding for i to fail to elaborate.

For i + 1, the special thing here is that the binop elaborator isn't able to do postponement if it fails to calculate a type for the expression, so it falls back to letting HAdd.hAdd elaborate like usual.

@nomeata
Copy link
Collaborator

nomeata commented Oct 27, 2024

Ok, sounds reasonable and matches the expectation that interpolatoin behaves like an implicit toMessageData.

@leanprover-community-bot leanprover-community-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Oct 27, 2024
@kmill kmill added this pull request to the merge queue Oct 27, 2024
Merged via the queue into leanprover:master with commit 709ea6c Oct 27, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants