lean-ja / lean-ja/lean-by-example

#see コマンド実装例

Open
#1,502 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

コード例 メタプログラミング
Dominant language
Lean
Stars
188
Forks
15
Avg merge
9h 8m
Merged PRs (30d)
6

Description

暗黙インスタンスを見つけているだけ?

see: https://leanprover.zulipchat.com/#narrow/channel/113489-new-members/topic/Need.20help.20understanding.20ring_nf/near/497758440

import Lean

open Lean Elab Command Meta

syntax (name := see) "#see" term : command

@[command_elab see]
def elabShow : CommandElab
  | `(#see%$tk $term) => withoutModifyingEnv <| runTermElabM fun _ => Term.withDeclName `_show do
    -- -- show signature for `#check id`/`#check @id`
    -- if let `($id:ident) := term then
    --   try
    --     for c in (← realizeGlobalConstWithInfos term) do
    --       addCompletionInfo <| .id term id.getId (danglingDot := false) {} none
    --       logInfoAt tk <| .signature c
    --       return
    --   catch _ => pure ()  -- identifier might not be a constant but constant + projection
    let e ← Term.elabTerm term none
    Term.synthesizeSyntheticMVarsNoPostponing (ignoreStuckTC := true)
    -- Users might be testing out buggy elaborators. Let's typecheck before proceeding:
    withRef tk <| Meta.check e
    let e ← Term.levelMVarToParam (← instantiateMVars e)
    if e.isSyntheticSorry then
      return
    let type ← inferType e
    let str : MessageData ← e.withApp fun f xs ↦
      return xs.foldl (fun m n ↦ m ++ m!" {n}") m!"{f}"
    logInfoAt tk <| str ++ m!" : {type}"
  | _ => throwUnsupportedSyntax

/--
info: @OfScientific.ofScientific Float instOfScientificFloat 27 true 2 : Float
-/
#guard_msgs in
#see 0.27

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

Start with the #see syntax and the elabShow command elaborator in the issue, then trace its uses of Term.elabTerm, Meta.check, and inferType. Compare the implementation with the linked Zulip discussion and confirm what the #see 0.27 output represents. Done means the example clearly documents whether implicit instances are being found.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.