on master help sign in
Fix whnfArgs naming error

In particular, we need to be aware that names can be rebound in the scope of whnfArgs, so don't instantiate the name after it's rebound. Fixes #3534

commit3a881e6ba2fea20b6ff303db4e10bdc2393de47c authorEdwin Brady <ecb10@st-andrews.ac.uk> dateTue 29 Nov 2016, 22:54 (10 years ago) parent4d574b9
3 files changed+45−2
src/Idris/Core/WHNF.hs+3−2 test/regression001/eff001.idr+39 test/regression001/run+3
src/Idris/Core/WHNF.hs+3−2
@@ -72,8 +72,9 @@ whnfArgs' ctxt env tm
7272 -- The assumption is that de Bruijn indices refer to local things
7373 -- (so not in the external environment) so we need to instantiate
7474 -- the name
75− Bind n b@(Pi _ ty _) sc -> Bind n b (whnfArgs' ctxt ((n,b):env)
76− (instantiate (P Bound n ty) sc))
75+ Bind n b@(Pi _ ty _) sc ->
76+ Bind n b (whnfArgs' ctxt ((n,b):env)
77+ (subst n (P Bound n ty) sc))
7778 res -> tm
7879
7980finalEntry :: (Name, Binder (TT Name)) -> (Name, Binder (TT Name))
test/regression001/eff001.idrnew file+39
@@ -0,0 +1,39 @@
1+module Test.Random
2+
3+import Effects
4+import Effect.Random
5+
6+genKVPair : (genA : Eff a [RND])
7+ -> (genB : Eff b [RND])
8+ -> Eff (Pair a b) [RND]
9+genKVPair f g = pure (!f, !g)
10+
11+genRndListKVUE : (Eq a, Eq b) =>
12+ (seed : Integer)
13+ -> (len : Nat)
14+ -> (genA : Eff a [RND])
15+ -> (genB : Eff b [RND])
16+ -> Eff (List (Pair a b)) [RND]
17+genRndListKVUE s l f g = do srand s; pure !(doGen l (genKVPair f g))
18+ where
19+ genElem : (Eq a, Eq b)
20+ => (generator : Eff (Pair a b) [RND])
21+ -> (existing : List (Pair a b))
22+ -> Eff (Pair a b) [RND]
23+ genElem j xs = do
24+ x <- j
25+ if elem x xs
26+ then genElem j xs
27+ else if isJust $ lookup (fst x) xs
28+ then genElem j xs
29+ else pure x
30+
31+ doGen : (Eq a, Eq b)
32+ => (count : Nat)
33+ -> (generator : Eff (Pair a b) [RND])
34+ -> Eff (List (Pair a b)) [RND]
35+ doGen Z j = pure Nil
36+ doGen (S n) j = do
37+ xs <- doGen n j
38+ x <- genElem j xs
39+ pure (x::xs)
test/regression001/run+3
@@ -5,6 +5,9 @@ ${IDRIS:-idris} $@ --check \
55 reg059.idr reg060.idr reg061.idr reg062.idr reg063.idr \
66 reg064.idr reg065.idr reg066.idr reg071.idr reg074.idr
77
8+${IDRIS:-idris} $@ --check \
9+ eff001.idr -p effects
10+
811${IDRIS:-idris} $@ --check --nobuiltins reg047.idr
912
1013${IDRIS:-idris} $@ --check --nocolour \