lean4-htt/tests/lean/run/interp2.lean
Kim Morrison 3a457e6ad6
chore: use #guard_msgs in run tests (#4175)
Many of our tests in `tests/lean/run/` produce output from `#eval` (or
`#check`) statements, that is then ignored.

This PR tries to capture all the useful output using `#guard_msgs`. I've
only done a cursory check that the output is still sane --- there is a
chance that some "unchecked" tests have already accumulated regressions
and this just cements them!

In the other direction, I did identify two rotten tests:
* a minor one in `setStructInstNotation.lean`, where a comment says `Set
Nat`, but `#check` actually prints `?_`. Weird?
* `CompilerProbe.lean` is generating empty output, apparently indicating
that something is broken, but I don't know the signficance of this file.

In any case, I'll ask about these elsewhere.

(This started by noticing that a recent `grind` test file had an
untested `trace_state`, and then got carried away.)
2024-05-16 00:38:31 +00:00

65 lines
2 KiB
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.

inductive Vector (α : Type u) : Nat → Type u
| nil : Vector α 0
| cons : α → Vector α n → Vector α (n+1)
infix:67 " :: " => Vector.cons
inductive Ty where
| int
| bool
| fn (a r : Ty)
abbrev Ty.interp : Ty → Type
| int => Int
| bool => Bool
| fn a r => a.interp → r.interp
inductive HasType : Fin n → Vector Ty n → Ty → Type where
| stop : HasType 0 (ty :: ctx) ty
| pop : HasType k ctx ty → HasType k.succ (u :: ctx) ty
inductive Expr : Vector Ty n → Ty → Type where
| var : HasType i ctx ty → Expr ctx ty
| val : Int → Expr ctx Ty.int
| lam : Expr (a :: ctx) ty → Expr ctx (Ty.fn a ty)
| app : Expr ctx (Ty.fn a ty) → Expr ctx a → Expr ctx ty
| op : (a.interp → b.interp → c.interp) → Expr ctx a → Expr ctx b → Expr ctx c
| ife : Expr ctx Ty.bool → Expr ctx a → Expr ctx a → Expr ctx a
| delay : (Unit → Expr ctx a) → Expr ctx a
inductive Env : Vector Ty n → Type where
| nil : Env Vector.nil
| cons : Ty.interp a → Env ctx → Env (a :: ctx)
infix:67 " :: " => Env.cons
def lookup : HasType i ctx ty → Env ctx → ty.interp
| .stop, x :: xs => x
| .pop k, x :: xs => lookup k xs
def interp (env : Env ctx) : Expr ctx ty → ty.interp := fun e =>
match e with
| .var i => lookup i env
| .val x => x
| .lam b => fun x => interp (x :: env) b
| .app f a => interp env f (interp env a)
| .op o x y => o (interp env x) (interp env y)
| .ife c t e => if interp env c then interp env t else interp env e
| .delay a => interp env (a ())
open Expr
/- Examples -/
def add : Expr ctx (Ty.fn Ty.int (Ty.fn Ty.int Ty.int)) :=
lam (lam (op (.+.) (var .stop) (var (.pop .stop))))
#guard interp Env.nil add 10 20 == 30
def fact : Expr ctx (Ty.fn Ty.int Ty.int) :=
lam (ife (op (.==.) (var .stop) (val 0))
(val 1)
(op (.*.) (delay fun _ => app fact (op (.-.) (var .stop) (val 1))) (var .stop)))
decreasing_by sorry
#guard interp Env.nil fact 10 == 3628800