@@ -3,18 +3,18 @@ import Lean.Meta
3
3
open Lean
4
4
open Lean.Meta
5
5
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
18
18
let (b, _, _) ← (isProp e : MetaM _).toIO { fileName := "" , fileMap := default } { env := env };
19
19
IO.println (toString e ++ ", isProp: " ++ toString b)
20
20
@@ -26,15 +26,15 @@ mkAppN map #[nat, bool]
26
26
27
27
/-- info: List.map.{1, 1} Nat Bool : (Nat -> Bool) -> (List.{1} Nat) -> (List.{1} Bool) -/
28
28
#guard_msgs in
29
- #eval tstInferType #[ `Init.Data.List] t1
29
+ #eval tstInferType t1
30
30
31
31
def t2 : Expr :=
32
32
let prop := mkSort levelZero;
33
33
mkForall `x BinderInfo.default prop prop
34
34
35
35
/-- info: Prop -> Prop : Type -/
36
36
#guard_msgs in
37
- #eval tstInferType #[ `Init.Core] t2
37
+ #eval tstInferType t2
38
38
39
39
def t3 : Expr :=
40
40
let nat := mkConst `Nat [];
@@ -45,7 +45,7 @@ mkForall `x BinderInfo.default nat p
45
45
46
46
/-- info: forall (x : Nat), Nat.le x 0 : Prop -/
47
47
#guard_msgs in
48
- #eval tstInferType #[ `Init.Data.Nat] t3
48
+ #eval tstInferType t3
49
49
50
50
def t4 : Expr :=
51
51
let nat := mkConst `Nat [];
@@ -54,19 +54,15 @@ mkLambda `x BinderInfo.default nat p
54
54
55
55
/-- info: fun (x : Nat) => Nat.succ x : Nat -> Nat -/
56
56
#guard_msgs in
57
- #eval tstInferType #[ `Init.Core] t4
57
+ #eval tstInferType t4
58
58
59
59
def t5 : Expr :=
60
60
let add := mkConst `Nat.add [];
61
61
mkAppN add #[mkLit (Literal.natVal 3 ), mkLit (Literal.natVal 5 )]
62
62
63
63
/-- info: Nat.add 3 5 ==> 8 -/
64
64
#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
70
66
71
67
set_option pp.all true
72
68
/-- info: @List.cons.{0} Nat : Nat → List.{0} Nat → List.{0} Nat -/
@@ -89,23 +85,23 @@ mkAppN map #[nat, nat, f, xs]
89
85
info: 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
90
86
-/
91
87
#guard_msgs in
92
- #eval tstInferType #[ `Init.Data.List] t6
88
+ #eval tstInferType t6
93
89
94
90
/--
95
91
info: 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)))
96
92
-/
97
93
#guard_msgs in
98
- #eval tstWHNF #[ `Init.Data.List] t6
94
+ #eval tstWHNF t6
99
95
100
96
/-- info: Prop : Type -/
101
97
#guard_msgs in
102
- #eval tstInferType #[] $ mkSort levelZero
98
+ #eval tstInferType $ mkSort levelZero
103
99
104
100
/--
105
101
info: fun {a : Type} (x : a) (xs : List.{0} a) => xs : forall {a : Type}, a -> (List.{0} a) -> (List.{0} a)
106
102
-/
107
103
#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 )))
109
105
110
106
def t7 : Expr :=
111
107
let nat := mkConst `Nat [];
@@ -114,11 +110,11 @@ mkLet `x nat one one
114
110
115
111
/-- info: let x : Nat := 1; 1 : Nat -/
116
112
#guard_msgs in
117
- #eval tstInferType #[ `Init.Core] $ t7
113
+ #eval tstInferType $ t7
118
114
119
115
/-- info: let x : Nat := 1; 1 ==> 1 -/
120
116
#guard_msgs in
121
- #eval tstWHNF #[ `Init.Core] $ t7
117
+ #eval tstWHNF $ t7
122
118
123
119
def t8 : Expr :=
124
120
let nat := mkConst `Nat [];
@@ -128,35 +124,35 @@ mkLet `x nat one (mkAppN add #[one, mkBVar 0])
128
124
129
125
/-- info: let x : Nat := 1; Nat.add 1 x : Nat -/
130
126
#guard_msgs in
131
- #eval tstInferType #[ `Init.Core] $ t8
127
+ #eval tstInferType $ t8
132
128
133
129
/-- info: let x : Nat := 1; Nat.add 1 x ==> 2 -/
134
130
#guard_msgs in
135
- #eval tstWHNF #[ `Init.Core] $ t8
131
+ #eval tstWHNF $ t8
136
132
137
133
def t9 : Expr :=
138
134
let nat := mkConst `Nat [];
139
135
mkLet `a (mkSort levelOne) nat (mkForall `x BinderInfo.default (mkBVar 0 ) (mkBVar 1 ))
140
136
141
137
/-- info: let a : Type := Nat; a -> a : Type -/
142
138
#guard_msgs in
143
- #eval tstInferType #[ `Init.Core] $ t9
139
+ #eval tstInferType $ t9
144
140
145
141
/-- info: let a : Type := Nat; a -> a ==> Nat -> Nat -/
146
142
#guard_msgs in
147
- #eval tstWHNF #[ `Init.Core] $ t9
143
+ #eval tstWHNF $ t9
148
144
149
145
/-- info: 10 : Nat -/
150
146
#guard_msgs in
151
- #eval tstInferType #[ `Init.Core] $ mkLit (Literal.natVal 10 )
147
+ #eval tstInferType $ mkLit (Literal.natVal 10 )
152
148
153
149
/-- info: "hello" : String -/
154
150
#guard_msgs in
155
- #eval tstInferType #[ `Init.Core] $ mkLit (Literal.strVal "hello" )
151
+ #eval tstInferType $ mkLit (Literal.strVal "hello" )
156
152
157
153
/-- info: [mdata 10] : Nat -/
158
154
#guard_msgs in
159
- #eval tstInferType #[ `Init.Core] $ mkMData {} $ mkLit (Literal.natVal 10 )
155
+ #eval tstInferType $ mkMData {} $ mkLit (Literal.natVal 10 )
160
156
161
157
def t10 : Expr :=
162
158
let nat := mkConst `Nat [];
@@ -165,39 +161,39 @@ mkLambda `a BinderInfo.default nat (mkApp refl (mkBVar 0))
165
161
166
162
/-- info: fun (a : Nat) => Eq.refl.{1} Nat a : forall (a : Nat), Eq.{1} Nat a a -/
167
163
#guard_msgs in
168
- #eval tstInferType #[ `Init.Core] t10
164
+ #eval tstInferType t10
169
165
170
166
/-- info: fun (a : Nat) => Eq.refl.{1} Nat a, isProp: false -/
171
167
#guard_msgs in
172
- #eval tstIsProp #[ `Init.Core] t10
168
+ #eval tstIsProp t10
173
169
174
170
/-- info: And True True, isProp: true -/
175
171
#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 []])
177
173
178
174
/-- info: And, isProp: false -/
179
175
#guard_msgs in
180
- #eval tstIsProp #[ `Init.Core] (mkConst `And [])
176
+ #eval tstIsProp (mkConst `And [])
181
177
182
178
-- Example where isPropQuick fails
183
179
/-- info: id.{0} Prop (And True True), isProp: true -/
184
180
#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
186
182
`True []]])
187
183
188
184
/-- info: Eq.{1} Nat 0 1, isProp: true -/
189
185
#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 )])
191
187
192
188
/-- info: forall (x : Nat), Eq.{1} Nat x 1, isProp: true -/
193
189
#guard_msgs in
194
- #eval tstIsProp #[ `Init.Core] $
190
+ #eval tstIsProp $
195
191
mkForall `x BinderInfo.default (mkConst `Nat [])
196
192
(mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkBVar 0 , mkLit (Literal.natVal 1 )])
197
193
198
194
/-- info: (fun (x : Nat) => Eq.{1} Nat x 1) 0, isProp: true -/
199
195
#guard_msgs in
200
- #eval tstIsProp #[ `Init.Core] $
196
+ #eval tstIsProp $
201
197
mkApp
202
198
(mkLambda `x BinderInfo.default (mkConst `Nat [])
203
199
(mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkBVar 0 , mkLit (Literal.natVal 1 )]))
0 commit comments