lean4-htt/tests/lean/run/toExpr.lean
Leonardo de Moura e54a207986 refactor: provide Options to lean_eval_const
add `ImportM` monad for `addImportedFn`

cc @Kha
2020-10-19 10:21:38 -07:00

31 lines
800 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
new_frontend
open Lean
unsafe def test {α : Type} [HasToString α] [ToExpr α] [HasBeq α] (a : α) : CoreM Unit := do
let env ← getEnv;
let auxName := `_toExpr._test;
let decl := Declaration.defnDecl {
name := auxName,
lparams := [],
value := toExpr a,
type := toTypeExpr α,
hints := ReducibilityHints.abbrev,
isUnsafe := false
};
IO.println (toExpr a);
(match env.addAndCompile {} decl with
| Except.error _ => throwError "addDecl failed"
| Except.ok env =>
match env.evalConst α {} auxName with
| Except.error ex => throwError ex
| Except.ok b => do
IO.println b;
«unless» (a == b) $
throwError "toExpr failed";
pure ())
#eval test #[(1, 2), (3, 4)]
#eval test ['a', 'b', 'c']
#eval test ("hello", true)
#eval test ((), 10)