@@ -3,18 +3,18 @@ import Lean.Meta
33open Lean
44open Lean.Meta
55
6- unsafe def tstInferType (mods : Array Name) ( e : Expr) : IO Unit :=
7- withImportModules (mods.map $ fun m => { module := m}) {} 0 fun env => do
8- let (type, _, _) ← (inferType e : MetaM _).toIO { fileName := "" , fileMap := default } { env := env } {} {};
9- IO.println (toString e ++ " : " ++ toString type)
10-
11- unsafe def tstWHNF (mods : Array Name) ( e : Expr) (t := TransparencyMode.default) : IO Unit :=
12- withImportModules (mods.map $ fun m => { module := m}) {} 0 fun env => do
13- let (s, _, _) ← (whnf e : MetaM _).toIO { fileName := "" , fileMap := default } { env := env };
14- IO.println (toString e ++ " ==> " ++ toString s)
15-
16- unsafe def tstIsProp (mods : Array Name) ( e : Expr) : IO Unit :=
17- withImportModules (mods.map $ fun m => { module := m}) {} 0 fun env => do
6+ def tstInferType (e : Expr) : CoreM Unit := do
7+ let env ← getEnv
8+ let (type, _, _) ← (inferType e : MetaM _).toIO { fileName := "" , fileMap := default } { env := env } {} {};
9+ IO.println (toString e ++ " : " ++ toString type)
10+
11+ def tstWHNF (e : Expr) : CoreM Unit := do
12+ let env ← getEnv
13+ let (s, _, _) ← (whnf e : MetaM _).toIO { fileName := "" , fileMap := default } { env := env };
14+ IO.println (toString e ++ " ==> " ++ toString s)
15+
16+ unsafe def tstIsProp (e : Expr) : CoreM Unit := do
17+ let env ← getEnv
1818 let (b, _, _) ← (isProp e : MetaM _).toIO { fileName := "" , fileMap := default } { env := env };
1919 IO.println (toString e ++ ", isProp: " ++ toString b)
2020
@@ -26,15 +26,15 @@ mkAppN map #[nat, bool]
2626
2727/-- info: List.map.{1, 1} Nat Bool : (Nat -> Bool) -> (List.{1} Nat) -> (List.{1} Bool) -/
2828#guard_msgs in
29- #eval tstInferType #[`Init.Data.List] t1
29+ #eval tstInferType t1
3030
3131def t2 : Expr :=
3232let prop := mkSort levelZero;
3333mkForall `x BinderInfo.default prop prop
3434
3535/-- info: Prop -> Prop : Type -/
3636#guard_msgs in
37- #eval tstInferType #[`Init.Core] t2
37+ #eval tstInferType t2
3838
3939def t3 : Expr :=
4040let nat := mkConst `Nat [];
@@ -45,7 +45,7 @@ mkForall `x BinderInfo.default nat p
4545
4646/-- info: forall (x : Nat), Nat.le x 0 : Prop -/
4747#guard_msgs in
48- #eval tstInferType #[`Init.Data.Nat] t3
48+ #eval tstInferType t3
4949
5050def t4 : Expr :=
5151let nat := mkConst `Nat [];
@@ -54,19 +54,15 @@ mkLambda `x BinderInfo.default nat p
5454
5555/-- info: fun (x : Nat) => Nat.succ x : Nat -> Nat -/
5656#guard_msgs in
57- #eval tstInferType #[`Init.Core] t4
57+ #eval tstInferType t4
5858
5959def t5 : Expr :=
6060let add := mkConst `Nat.add [];
6161mkAppN add #[mkLit (Literal.natVal 3 ), mkLit (Literal.natVal 5 )]
6262
6363/-- info: Nat.add 3 5 ==> 8 -/
6464#guard_msgs in
65- #eval tstWHNF #[`Init.Data.Nat] t5
66-
67- /-- info: Nat.add 3 5 ==> 8 -/
68- #guard_msgs in
69- #eval tstWHNF #[`Init.Data.Nat] t5 TransparencyMode.reducible
65+ #eval tstWHNF t5
7066
7167set_option pp.all true
7268/-- info: @List.cons.{0} Nat : Nat → List.{0} Nat → List.{0} Nat -/
@@ -89,23 +85,23 @@ mkAppN map #[nat, nat, f, xs]
8985info: List.map.{1, 1} Nat Nat (fun (x : Nat) => Nat.add x 1) (List.cons.{0} Nat 1 (List.cons.{0} Nat 4 (List.nil.{0} Nat))) : List.{1} Nat
9086-/
9187#guard_msgs in
92- #eval tstInferType #[`Init.Data.List] t6
88+ #eval tstInferType t6
9389
9490/--
9591info: List.map.{1, 1} Nat Nat (fun (x : Nat) => Nat.add x 1) (List.cons.{0} Nat 1 (List.cons.{0} Nat 4 (List.nil.{0} Nat))) ==> List.cons.{1} Nat ((fun (x : Nat) => Nat.add x 1) 1) (List.map.{1, 1} Nat Nat (fun (x : Nat) => Nat.add x 1) (List.cons.{0} Nat 4 (List.nil.{0} Nat)))
9692-/
9793#guard_msgs in
98- #eval tstWHNF #[`Init.Data.List] t6
94+ #eval tstWHNF t6
9995
10096/-- info: Prop : Type -/
10197#guard_msgs in
102- #eval tstInferType #[] $ mkSort levelZero
98+ #eval tstInferType $ mkSort levelZero
10399
104100/--
105101info: fun {a : Type} (x : a) (xs : List.{0} a) => xs : forall {a : Type}, a -> (List.{0} a) -> (List.{0} a)
106102-/
107103#guard_msgs in
108- #eval tstInferType #[`Init.Data.List] $ mkLambda `a BinderInfo.implicit (mkSort levelOne) (mkLambda `x BinderInfo.default (mkBVar 0 ) (mkLambda `xs BinderInfo.default (mkApp (mkConst `List [levelZero]) (mkBVar 1 )) (mkBVar 0 )))
104+ #eval tstInferType $ mkLambda `a BinderInfo.implicit (mkSort levelOne) (mkLambda `x BinderInfo.default (mkBVar 0 ) (mkLambda `xs BinderInfo.default (mkApp (mkConst `List [levelZero]) (mkBVar 1 )) (mkBVar 0 )))
109105
110106def t7 : Expr :=
111107let nat := mkConst `Nat [];
@@ -114,11 +110,11 @@ mkLet `x nat one one
114110
115111/-- info: let x : Nat := 1; 1 : Nat -/
116112#guard_msgs in
117- #eval tstInferType #[`Init.Core] $ t7
113+ #eval tstInferType $ t7
118114
119115/-- info: let x : Nat := 1; 1 ==> 1 -/
120116#guard_msgs in
121- #eval tstWHNF #[`Init.Core] $ t7
117+ #eval tstWHNF $ t7
122118
123119def t8 : Expr :=
124120let nat := mkConst `Nat [];
@@ -128,35 +124,35 @@ mkLet `x nat one (mkAppN add #[one, mkBVar 0])
128124
129125/-- info: let x : Nat := 1; Nat.add 1 x : Nat -/
130126#guard_msgs in
131- #eval tstInferType #[`Init.Core] $ t8
127+ #eval tstInferType $ t8
132128
133129/-- info: let x : Nat := 1; Nat.add 1 x ==> 2 -/
134130#guard_msgs in
135- #eval tstWHNF #[`Init.Core] $ t8
131+ #eval tstWHNF $ t8
136132
137133def t9 : Expr :=
138134let nat := mkConst `Nat [];
139135mkLet `a (mkSort levelOne) nat (mkForall `x BinderInfo.default (mkBVar 0 ) (mkBVar 1 ))
140136
141137/-- info: let a : Type := Nat; a -> a : Type -/
142138#guard_msgs in
143- #eval tstInferType #[`Init.Core] $ t9
139+ #eval tstInferType $ t9
144140
145141/-- info: let a : Type := Nat; a -> a ==> Nat -> Nat -/
146142#guard_msgs in
147- #eval tstWHNF #[`Init.Core] $ t9
143+ #eval tstWHNF $ t9
148144
149145/-- info: 10 : Nat -/
150146#guard_msgs in
151- #eval tstInferType #[`Init.Core] $ mkLit (Literal.natVal 10 )
147+ #eval tstInferType $ mkLit (Literal.natVal 10 )
152148
153149/-- info: "hello" : String -/
154150#guard_msgs in
155- #eval tstInferType #[`Init.Core] $ mkLit (Literal.strVal "hello" )
151+ #eval tstInferType $ mkLit (Literal.strVal "hello" )
156152
157153/-- info: [mdata 10] : Nat -/
158154#guard_msgs in
159- #eval tstInferType #[`Init.Core] $ mkMData {} $ mkLit (Literal.natVal 10 )
155+ #eval tstInferType $ mkMData {} $ mkLit (Literal.natVal 10 )
160156
161157def t10 : Expr :=
162158let nat := mkConst `Nat [];
@@ -165,39 +161,39 @@ mkLambda `a BinderInfo.default nat (mkApp refl (mkBVar 0))
165161
166162/-- info: fun (a : Nat) => Eq.refl.{1} Nat a : forall (a : Nat), Eq.{1} Nat a a -/
167163#guard_msgs in
168- #eval tstInferType #[`Init.Core] t10
164+ #eval tstInferType t10
169165
170166/-- info: fun (a : Nat) => Eq.refl.{1} Nat a, isProp: false -/
171167#guard_msgs in
172- #eval tstIsProp #[`Init.Core] t10
168+ #eval tstIsProp t10
173169
174170/-- info: And True True, isProp: true -/
175171#guard_msgs in
176- #eval tstIsProp #[`Init.Core] (mkAppN (mkConst `And []) #[mkConst `True [], mkConst `True []])
172+ #eval tstIsProp (mkAppN (mkConst `And []) #[mkConst `True [], mkConst `True []])
177173
178174/-- info: And, isProp: false -/
179175#guard_msgs in
180- #eval tstIsProp #[`Init.Core] (mkConst `And [])
176+ #eval tstIsProp (mkConst `And [])
181177
182178-- Example where isPropQuick fails
183179/-- info: id.{0} Prop (And True True), isProp: true -/
184180#guard_msgs in
185- #eval tstIsProp #[`Init.Core] (mkAppN (mkConst `id [levelZero]) #[mkSort levelZero, mkAppN (mkConst `And []) #[mkConst `True [], mkConst
181+ #eval tstIsProp (mkAppN (mkConst `id [levelZero]) #[mkSort levelZero, mkAppN (mkConst `And []) #[mkConst `True [], mkConst
186182 `True []]])
187183
188184/-- info: Eq.{1} Nat 0 1, isProp: true -/
189185#guard_msgs in
190- #eval tstIsProp #[`Init.Core] (mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkLit (Literal.natVal 0 ), mkLit (Literal.natVal 1 )])
186+ #eval tstIsProp (mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkLit (Literal.natVal 0 ), mkLit (Literal.natVal 1 )])
191187
192188/-- info: forall (x : Nat), Eq.{1} Nat x 1, isProp: true -/
193189#guard_msgs in
194- #eval tstIsProp #[`Init.Core] $
190+ #eval tstIsProp $
195191 mkForall `x BinderInfo.default (mkConst `Nat [])
196192 (mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkBVar 0 , mkLit (Literal.natVal 1 )])
197193
198194/-- info: (fun (x : Nat) => Eq.{1} Nat x 1) 0, isProp: true -/
199195#guard_msgs in
200- #eval tstIsProp #[`Init.Core] $
196+ #eval tstIsProp $
201197 mkApp
202198 (mkLambda `x BinderInfo.default (mkConst `Nat [])
203199 (mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkBVar 0 , mkLit (Literal.natVal 1 )]))
0 commit comments