@@ -4,7 +4,7 @@ open import Lam.Data
4
4
open import Lam.Evaluator
5
5
open import Lam.UtilsAgda
6
6
7
- open import Haskell.Prelude using (Just; Nothing; Int; Bool; _+_; _-_; _*_; _&&_; _||_; not)
7
+ open import Haskell.Prelude using (Just; Nothing; Int; Bool; _+_; _-_; _*_; _&&_; _||_; not; _<_ )
8
8
9
9
open import Data.Bool using (true; false)
10
10
open import Data.Empty using (⊥-elim; ⊥)
@@ -58,6 +58,13 @@ data Neutral where
58
58
---------------------
59
59
→ Neutral (BinOp Mul L M)
60
60
61
+ noe-ltInt : ∀ {L M : Expr}
62
+ → Normal L
63
+ → Normal M
64
+ → (∀ {i j : Int} → ¬ (L ≡ (Const (NumC i)) × M ≡ (Const (NumC j))))
65
+ ---------------------
66
+ → Neutral (BinOp LtInt L M)
67
+
61
68
noe-and : ∀ {L M : Expr}
62
69
→ Normal L
63
70
→ Normal M
@@ -140,7 +147,7 @@ data ReducesTo : Expr → Expr → Set where
140
147
→ Normal V1
141
148
→ Normal V2
142
149
---------------------------
143
- → ReducesTo (App (Lam s ty V1) V2) (substitute V1 V2 )
150
+ → ReducesTo (App (Lam s ty V1) V2) (substitute V2 V1 )
144
151
-- using a predicate to specify substitution here gets pretty ugly
145
152
146
153
r-l' : ∀ {s : Id} {ty : TypeL} {L L' : Expr}
@@ -168,6 +175,9 @@ data ReducesTo : Expr → Expr → Set where
168
175
r-mul : ∀ {i1 i2 : Int}
169
176
→ ReducesTo (BinOp Mul (Const (NumC i1)) (Const (NumC i2))) (Const (NumC (i1 * i2)))
170
177
178
+ r-ltInt : ∀ {i1 i2 : Int}
179
+ → ReducesTo (BinOp LtInt (Const (NumC i1)) (Const (NumC i2))) (Const (BoolC (i1 < i2)))
180
+
171
181
r-and : ∀ {i1 i2 : Bool}
172
182
→ ReducesTo (BinOp And (Const (BoolC i1)) (Const (BoolC i2))) (Const (BoolC (i1 && i2)))
173
183
@@ -290,6 +300,11 @@ stepNothingNormal {BinOp Mul L M} eq | Nothing | Nothing =
290
300
where
291
301
mulStepNothing : ∀ {i j} → smallStepBinOp Mul L M Nothing Nothing ≡ Nothing → ¬ ((L ≡ Const (NumC i)) × (M ≡ Const (NumC j)))
292
302
mulStepNothing () ⟨ refl , refl ⟩
303
+ stepNothingNormal {BinOp LtInt L M} eq | Nothing | Nothing =
304
+ no-ne (noe-ltInt (stepNothingNormal eqL) (stepNothingNormal eqM) (ltStepNothing eq))
305
+ where
306
+ ltStepNothing : ∀ {i j} → smallStepBinOp LtInt L M Nothing Nothing ≡ Nothing → ¬ ((L ≡ Const (NumC i)) × (M ≡ Const (NumC j)))
307
+ ltStepNothing () ⟨ refl , refl ⟩
293
308
stepNothingNormal {BinOp And L M} eq | Nothing | Nothing =
294
309
no-ne (noe-and (stepNothingNormal eqL) (stepNothingNormal eqM) (andStepNothing eq))
295
310
where
@@ -368,6 +383,11 @@ neutralStepNothing {BinOp Mul L M} (noe-mul h1 h2 h3)
368
383
| normalStepNothing h2 with smallStepBinOp Mul L M Nothing Nothing in eq
369
384
neutralStepNothing {BinOp Mul L M} (noe-mul h1 h2 h3) | Nothing = refl
370
385
neutralStepNothing {BinOp Mul (Const (NumC L')) (Const (NumC M'))} (noe-mul h1 h2 h3) | Just V' = ⊥-elim (h3 {L'} {M'} ⟨ refl , refl ⟩)
386
+ neutralStepNothing {BinOp LtInt L M} (noe-ltInt h1 h2 h3)
387
+ rewrite normalStepNothing h1
388
+ | normalStepNothing h2 with smallStepBinOp LtInt L M Nothing Nothing in eq
389
+ neutralStepNothing {BinOp LtInt L M} (noe-ltInt h1 h2 h3) | Nothing = refl
390
+ neutralStepNothing {BinOp LtInt (Const (NumC L')) (Const (NumC M'))} (noe-ltInt h1 h2 h3) | Just V' = ⊥-elim (h3 {L'} {M'} ⟨ refl , refl ⟩)
371
391
neutralStepNothing {BinOp And L M} (noe-and h1 h2 h3)
372
392
rewrite normalStepNothing h1
373
393
| normalStepNothing h2 with smallStepBinOp And L M Nothing Nothing in eq
@@ -421,6 +441,8 @@ step→red {BinOp Sub (Const (NumC i)) M} {N} h | Nothing | Nothing with M
421
441
... | Const (NumC j) rewrite sym (Just-injective h) = r-sub
422
442
step→red {BinOp Mul (Const (NumC i)) M} {N} h | Nothing | Nothing with M
423
443
... | Const (NumC j) rewrite sym (Just-injective h) = r-mul
444
+ step→red {BinOp LtInt (Const (NumC i)) M} {N} h | Nothing | Nothing with M
445
+ ... | Const (NumC j) rewrite sym (Just-injective h) = r-ltInt
424
446
step→red {BinOp And (Const (BoolC i)) M} {N} h | Nothing | Nothing with M
425
447
... | Const (BoolC j) rewrite sym (Just-injective h) = r-and
426
448
step→red {BinOp Or (Const (BoolC i)) M} {N} h | Nothing | Nothing with M
@@ -457,6 +479,7 @@ red→step (r-binop1 h) rewrite red→step h = refl
457
479
red→step (r-binop2 x h) rewrite normalStepNothing x | red→step h = refl
458
480
red→step r-sub = refl
459
481
red→step r-mul = refl
482
+ red→step r-ltInt = refl
460
483
red→step r-and = refl
461
484
red→step r-or = refl
462
485
red→step r-ite-true = refl
0 commit comments