lean-ja / lean-ja/lean-by-example
#see コマンド実装例
Open
Nobody has claimed this yet.
コード例
メタプログラミング
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
暗黙インスタンスを見つけているだけ?
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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