on master help sign in
Alpha conversion in substTerm

There may be explicit names at this stage, so we need to explicitly remember them. Fixes #3181

commit76d57f27ed8cfd97502d789adbc512578d490dd1 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateFri 27 May 2016, 09:43 (10 years ago) parentbf108b6
5 files changed+45−1
idris.cabal+3 src/Idris/Core/TT.hs+15−1 test/reg073/expected test/reg073/reg073.lidr+24 test/reg073/run+3
idris.cabal+3
@@ -335,6 +335,9 @@ Extra-source-files:
335335 test/reg072/run
336336 test/reg072/*.idr
337337 test/reg072/expected
338+ test/reg073/run
339+ test/reg073/*.lidr
340+ test/reg073/expected
338341
339342
340343 test/basic001/run
src/Idris/Core/TT.hs+15−1
@@ -1302,11 +1302,25 @@ substTerm :: Eq n => TT n {-^ Old term -} ->
13021302 TT n {-^ template term -}
13031303 -> TT n
13041304substTerm old new = st where
1305− st t | t == old = new
1305+ st t | eqAlpha [] t old = new
13061306 st (App s f a) = App s (st f) (st a)
13071307 st (Bind x b sc) = Bind x (fmap st b) (st sc)
13081308 st t = t
13091309
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+
13101324-- | Return number of occurrences of V 0 or bound name i the term
13111325occurrences :: Eq n => n -> TT n -> Int
13121326occurrences 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