on master help sign in
Alpha conversion in substTerm
76d57f2Edwin Brady
idris.cabal+3
@@ -335,6 +335,9 @@ Extra-source-files:
335 test/reg072/run
335 test/reg072/run
336 test/reg072/*.idr
336 test/reg072/*.idr
337 test/reg072/expected
337 test/reg072/expected
338+ test/reg073/run
339+ test/reg073/*.lidr
340+ test/reg073/expected
338
341
339
342
340 test/basic001/run
343 test/basic001/run
src/Idris/Core/TT.hs+15−1
@@ -1302,11 +1302,25 @@ substTerm :: Eq n => TT n {-^ Old term -} ->
1302 TT n {-^ template term -}
1302 TT n {-^ template term -}
1303 -> TT n
1303 -> TT n
1304substTerm old new = st where
1304substTerm old new = st where
1305− st t | t == old = new
1305+ st t | eqAlpha [] t old = new
1306 st (App s f a) = App s (st f) (st a)
1306 st (App s f a) = App s (st f) (st a)
1307 st (Bind x b sc) = Bind x (fmap st b) (st sc)
1307 st (Bind x b sc) = Bind x (fmap st b) (st sc)
1308 st t = t
1308 st t = t
1309
1309
1310+ eqAlpha as (P _ x _) (P _ y _)
1311+ = x == y || (x, y) `elem` as || (y, x) `elem` as
1312+ eqAlpha as (V x) (V y) = x == y
1313+ eqAlpha as (Bind x xb xs) (Bind y yb ys)
1314+ = eqAlphaB as xb yb && eqAlpha ((x, y) : as) xs ys
1315+ eqAlpha as (App _ fx ax) (App _ fy ay) = eqAlpha as fx fy && eqAlpha as ax ay
1316+ eqAlpha as x y = x == y
1317+
1318+ eqAlphaB as (Let xt xv) (Let yt yv)
1319+ = eqAlpha as xt yt && eqAlpha as xv yv
1320+ eqAlphaB as (Guess xt xv) (Guess yt yv)
1321+ = eqAlpha as xt yt && eqAlpha as xv yv
1322+ eqAlphaB as bx by = eqAlpha as (binderTy bx) (binderTy by)
1323+
1310-- | Return number of occurrences of V 0 or bound name i the term
1324-- | Return number of occurrences of V 0 or bound name i the term
1311occurrences :: Eq n => n -> TT n -> Int
1325occurrences :: Eq n => n -> TT n -> Int
1312occurrences n t = execState (no' 0 t) 0
1326occurrences n t = execState (no' 0 t) 0
test/reg073/expectednew file

No changes to the content.

test/reg073/reg073.lidrnew file+24
@@ -0,0 +1,24 @@
1+> %default total
2+> %auto_implicits off
3+
4+> postulate decLT : (m : Nat) -> (n : Nat) -> Dec (LT m n)
5+> postulate last : Nat
6+
7+> LTB : Nat -> Type
8+> LTB b = DPair Nat (\ n => LT n b)
9+
10+> Foo : (t : Nat) -> Type
11+> Foo t = LTB (S last)
12+
13+> Bar : {t : Nat} -> (n : Nat) -> Foo t -> Type
14+> Bar Z _ = Unit
15+> Bar (S n) x with (decLT (fst x) last)
16+> | (Yes _) = Unit
17+> | (No _) = Void
18+
19+> lemma : {t : Nat} -> {m : Nat} -> {x : Foo t} ->
20+> (fst x) `LT` last -> Bar (S m) x = Unit
21+> lemma {m} {x} prf with (decLT (fst x) last)
22+> | (Yes _) = Refl
23+> | (No contra) = void (contra prf)
24+
test/reg073/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} $@ reg073.lidr --check
3+rm -f *.ibc