@@ -6,7 +6,7 @@ import Decidable.Equality
6%default total
6%default total
7%language FirstClassReflection
7%language FirstClassReflection
9−using (xs : List a, ys : List a, G : List (List a))
9+using (xs : List a, ys : List a, gam : List (List a))
11 data Elem : a -> List a -> Type where
11 data Elem : a -> List a -> Type where
12 Stop : Elem x (x :: xs)
12 Stop : Elem x (x :: xs)
@@ -16,20 +16,20 @@ using (xs : List a, ys : List a, G : List (List a))
16-- and over a set of list variables.
16-- and over a set of list variables.
18 data Expr : List (List a) -> List a -> Type where
18 data Expr : List (List a) -> List a -> Type where
19− App : Expr G xs -> Expr G ys -> Expr G (xs ++ ys)
19+ App : Expr gam xs -> Expr gam ys -> Expr gam (xs ++ ys)
20− Var : Elem xs G -> Expr G xs
20+ Var : Elem xs gam -> Expr gam xs
21− ENil : Expr G []
21+ ENil : Expr gam []
23-- Reflection of list equalities, indexed over the concrete equality.
23-- Reflection of list equalities, indexed over the concrete equality.
25 data ListEq : List (List a) -> Type -> Type where
25 data ListEq : List (List a) -> Type -> Type where
26− EqP : Expr G xs -> Expr G ys -> ListEq G (xs = ys)
26+ EqP : Expr gam xs -> Expr gam ys -> ListEq gam (xs = ys)
28-- Fully right associative list expressions
28-- Fully right associative list expressions
30 data RExpr : List (List a) -> List a -> Type where
30 data RExpr : List (List a) -> List a -> Type where
31− RApp : RExpr G xs -> Elem ys G -> RExpr G (xs ++ ys)
31+ RApp : RExpr gam xs -> Elem ys gam -> RExpr gam (xs ++ ys)
32− RNil : RExpr G []
32+ RNil : RExpr gam []
34-- Convert an expression to a right associative expression, and return
34-- Convert an expression to a right associative expression, and return
35-- a proof that the rewriting has an equal interpretation to the original
35-- a proof that the rewriting has an equal interpretation to the original
@@ -38,7 +38,7 @@ using (xs : List a, ys : List a, G : List (List a))
38-- The idea is that we use this proof to build a proof of equality of
38-- The idea is that we use this proof to build a proof of equality of
39-- list appends
39-- list appends
41− expr_r : Expr G xs -> (xs' ** (RExpr G xs', xs = xs'))
41+ expr_r : Expr gam xs -> (xs' ** (RExpr gam xs', xs = xs'))
42 expr_r ENil = (_ ** (RNil, Refl))
42 expr_r ENil = (_ ** (RNil, Refl))
43 expr_r (Var i) = (_ ** (RApp RNil i, Refl))
43 expr_r (Var i) = (_ ** (RApp RNil i, Refl))
44 expr_r (App ex ey) = let (xl ** (xr, xprf)) = expr_r ex in
44 expr_r (App ex ey) = let (xl ** (xr, xprf)) = expr_r ex in
@@ -46,29 +46,29 @@ using (xs : List a, ys : List a, G : List (List a))
46 appRExpr _ _ xr yr xprf yprf
46 appRExpr _ _ xr yr xprf yprf
48 appRExpr : (xs', ys' : List a) ->
48 appRExpr : (xs', ys' : List a) ->
49− {G : List (List a)} -> {xs, ys : List a} ->
49+ {gam : List (List a)} -> {xs, ys : List a} ->
50− RExpr G xs -> RExpr G ys -> (xs' = xs) -> (ys' = ys) ->
50+ RExpr gam xs -> RExpr gam ys -> (xs' = xs) -> (ys' = ys) ->
51− (ws' ** (RExpr G ws', xs' ++ ys' = ws'))
51+ (ws' ** (RExpr gam ws', xs' ++ ys' = ws'))
52 appRExpr x' y' rxs (RApp e i) xprf yprf
52 appRExpr x' y' rxs (RApp e i) xprf yprf
53 = let (xs ** (rec, prf)) = appRExpr _ _ rxs e Refl Refl in
53 = let (xs ** (rec, prf)) = appRExpr _ _ rxs e Refl Refl in
54 (_ ** (RApp rec i, ?appRExpr1))
54 (_ ** (RApp rec i, ?appRExpr1))
55 appRExpr x' y' rxs RNil xprf yprf = (_ ** (rxs, ?appRExpr2))
55 appRExpr x' y' rxs RNil xprf yprf = (_ ** (rxs, ?appRExpr2))
57− r_expr : RExpr G xs -> Expr G xs
57+ r_expr : RExpr gam xs -> Expr gam xs
58 r_expr RNil = ENil
58 r_expr RNil = ENil
59 r_expr (RApp xs i) = App (r_expr xs) (Var i)
59 r_expr (RApp xs i) = App (r_expr xs) (Var i)
61-- Convert an expression to some other equivalent expression (which
61-- Convert an expression to some other equivalent expression (which
62-- just happens to be normalised to right associative form)
62-- just happens to be normalised to right associative form)
64− reduce : Expr G xs -> (xs' ** (Expr G xs', xs = xs'))
64+ reduce : Expr gam xs -> (xs' ** (Expr gam xs', xs = xs'))
65 reduce e = let (x' ** (e', prf)) = expr_r e in
65 reduce e = let (x' ** (e', prf)) = expr_r e in
66 (x' ** (r_expr e', prf))
66 (x' ** (r_expr e', prf))
68-- Build a proof that two expressions are equal. If they are, we'll know
68-- Build a proof that two expressions are equal. If they are, we'll know
69-- that the indices are equal.
69-- that the indices are equal.
71− eqExpr : (e : Expr G xs) -> (e' : Expr G ys) ->
71+ eqExpr : (e : Expr gam xs) -> (e' : Expr gam ys) ->
72 Maybe (e = e')
72 Maybe (e = e')
73 eqExpr (App x y) (App x' y') with (eqExpr x x', eqExpr y y')
73 eqExpr (App x y) (App x' y') with (eqExpr x x', eqExpr y y')
74 eqExpr (App x y) (App x y) | (Just Refl, Just Refl) = Just Refl
74 eqExpr (App x y) (App x y) | (Just Refl, Just Refl) = Just Refl
@@ -83,20 +83,20 @@ using (xs : List a, ys : List a, G : List (List a))
83-- they are equal
83-- they are equal
85 buildProof : {xs : List a} -> {ys : List a} ->
85 buildProof : {xs : List a} -> {ys : List a} ->
86− Expr G ln -> Expr G rn ->
86+ Expr gam ln -> Expr gam rn ->
87 (xs = ln) -> (ys = rn) -> Maybe (xs = ys)
87 (xs = ln) -> (ys = rn) -> Maybe (xs = ys)
88 buildProof e e' lp rp with (eqExpr e e')
88 buildProof e e' lp rp with (eqExpr e e')
89 buildProof e e lp rp | Just Refl = ?bp1
89 buildProof e e lp rp | Just Refl = ?bp1
90 buildProof e e' lp rp | Nothing = Nothing
90 buildProof e e' lp rp | Nothing = Nothing
92− testEq : Expr G xs -> Expr G ys -> Maybe (xs = ys)
92+ testEq : Expr gam xs -> Expr gam ys -> Maybe (xs = ys)
93 testEq l r = let (ln ** (l', lPrf)) = reduce l in
93 testEq l r = let (ln ** (l', lPrf)) = reduce l in
94 let (rn ** (r', rPrf)) = reduce r in
94 let (rn ** (r', rPrf)) = reduce r in
95 buildProof l' r' lPrf rPrf
95 buildProof l' r' lPrf rPrf
97-- Given a reflected equality, try to produce a proof that holds
97-- Given a reflected equality, try to produce a proof that holds
99− prove : ListEq G t -> Maybe t
99+ prove : ListEq gam t -> Maybe t
100 prove (EqP xs ys) = testEq xs ys
100 prove (EqP xs ys) = testEq xs ys
102 getJust : (x : Maybe a) -> IsJust x -> a
102 getJust : (x : Maybe a) -> IsJust x -> a
@@ -114,15 +114,15 @@ using (xs : List a, ys : List a, G : List (List a))
114 isElem x (x :: ys) | Just Refl = [| Stop |]
114 isElem x (x :: ys) | Just Refl = [| Stop |]
115 isElem x (y :: ys) | Nothing = [| Pop (isElem x ys) |]
115 isElem x (y :: ys) | Nothing = [| Pop (isElem x ys) |]
117− weakenElem : (G' : List a) -> Elem x xs -> Elem x (G' ++ xs)
117+ weakenElem : (gam' : List a) -> Elem x xs -> Elem x (gam' ++ xs)
118 weakenElem [] p = p
118 weakenElem [] p = p
119− weakenElem (g :: G) p = Pop (weakenElem G p)
119+ weakenElem (g :: gam) p = Pop (weakenElem gam p)
121− weaken : (G' : List (List a)) ->
121+ weaken : (gam' : List (List a)) ->
122− Expr G xs -> Expr (G' ++ G) xs
122+ Expr gam xs -> Expr (gam' ++ gam) xs
123− weaken G' (App l r) = App (weaken G' l) (weaken G' r)
123+ weaken gam' (App l r) = App (weaken gam' l) (weaken gam' r)
124− weaken G' (Var x) = Var (weakenElem G' x)
124+ weaken gam' (Var x) = Var (weakenElem gam' x)
125− weaken G' ENil = ENil
125+ weaken gam' ENil = ENil
128-- Now, some reflection magic.
128-- Now, some reflection magic.
@@ -133,21 +133,21 @@ using (xs : List a, ys : List a, G : List (List a))
133-- reduction will work the right way.
133-- reduction will work the right way.
135%reflection
135%reflection
136−reflectList : (G : List (List a)) ->
136+reflectList : (gam : List (List a)) ->
137− (xs : List a) -> (G' ** Expr (G' ++ G) xs)
137+ (xs : List a) -> (gam' ** Expr (gam' ++ gam) xs)
138−reflectList G [] = ([] ** ENil)
138+reflectList gam [] = ([] ** ENil)
140−reflectList G (x :: xs) with (reflectList G xs)
140+reflectList gam (x :: xs) with (reflectList gam xs)
141− | (G' ** xs') with (isElem (List.(::) x []) (G' ++ G))
141+ | (gam' ** xs') with (isElem (List.(::) x []) (gam' ++ gam))
142− | Just p = (G' ** App (Var p) xs')
142+ | Just p = (gam' ** App (Var p) xs')
143− | Nothing = ([x] :: G' ** App (Var Stop) (weaken [[x]] xs'))
143+ | Nothing = ([x] :: gam' ** App (Var Stop) (weaken [[x]] xs'))
145−reflectList G (xs ++ ys) with (reflectList G xs)
145+reflectList gam (xs ++ ys) with (reflectList gam xs)
146− | (G' ** xs') with (reflectList (G' ++ G) ys)
146+ | (gam' ** xs') with (reflectList (gam' ++ gam) ys)
147− | (G'' ** ys') = ((G'' ++ G') **
147+ | (gam'' ** ys') = ((gam'' ++ gam') **
148− rewrite (sym (appendAssociative G'' G' G)) in
148+ rewrite (sym (appendAssociative gam'' gam' gam)) in
149− App (weaken G'' xs') ys')
149+ App (weaken gam'' xs') ys')
150−reflectList G t with (isElem t G)
150+reflectList gam t with (isElem t gam)
151 | Just p = ([] ** Var p)
151 | Just p = ([] ** Var p)
152 | Nothing = ([t] ** Var Stop)
152 | Nothing = ([t] ** Var Stop)
@@ -160,12 +160,12 @@ reflectList G t with (isElem t G)
160-- forms of equality proofs anyway.
160-- forms of equality proofs anyway.
162%reflection
162%reflection
163−reflectEq : (a : Type) -> (G : List (List a)) -> (P : Type) -> (G' ** ListEq (G' ++ G) P)
163+reflectEq : (a : Type) -> (gam : List (List a)) -> (P : Type) -> (gam' ** ListEq (gam' ++ gam) P)
164−reflectEq a G (the (List a) xs = the (List a) ys) with (reflectList G xs)
164+reflectEq a gam (the (List a) xs = the (List a) ys) with (reflectList gam xs)
165− | (G' ** xs') with (reflectList (G' ++ G) ys)
165+ | (gam' ** xs') with (reflectList (gam' ++ gam) ys)
166− | (G'' ** ys') = ((G'' ++ G') **
166+ | (gam'' ** ys') = ((gam'' ++ gam') **
167− rewrite (sym (appendAssociative G'' G' G)) in
167+ rewrite (sym (appendAssociative gam'' gam' gam)) in
168− EqP (weaken G'' xs') ys')
168+ EqP (weaken gam'' xs') ys')
171-- Need these before we can test it or the reductions won't normalise fully...
171-- Need these before we can test it or the reductions won't normalise fully...