lean4-htt/tests/lean/run/ppRoundtripDefs.lean
2021-06-13 00:06:27 +02:00

26 lines
908 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean
open Lean Lean.Meta Lean.Elab Lean.Elab.Term Lean.Elab.Command Lean.PrettyPrinter
syntax (name := roundtrip) "#roundtrip " ident : command
@[commandElab roundtrip] def elabRoundtrip : CommandElab
| `(#roundtrip%$tk $name:ident) => withoutModifyingEnv do
let [name] ← resolveGlobalConst name.getId | throwError "cannot resolve name"
let some cInfo ← (← getEnv).find? name | throwError "no such decl: {name}"
let ns := cInfo.name.getRoot
let cmdStx ← liftTermElabM none do
let typeStx ← delab ns [] cInfo.type {}
let valueStx ← delab ns [] cInfo.value! {}
`(noncomputable def $(mkIdent (ns ++ `foo)):declId : $typeStx:term := $valueStx:term)
elabCommand cmdStx
| _ => throwUnsupportedSyntax
#roundtrip Nat.add
#roundtrip Std.Range.forIn.loop
def hasMonadInst {α : Type u} {m : Type u → Type v} [Monad m] (x : m α) : m α := x
#roundtrip hasMonadInst