@@ -20,56 +20,56 @@ export
2020data Var = MkVar -- Phantom, just for labelling purposes
2121
2222{- Contexts for holding current resources states -}
23−namespace Context
23+namespace Resources
2424 public export
25− data Context : Type where
26− Nil : Context
27− (::) : Resource -> Context -> Context
25+ data Resources : Type where
26+ Nil : Resources
27+ (::) : Resource -> Resources -> Resources
2828
2929 public export
30− (++) : Context -> Context -> Context
30+ (++) : Resources -> Resources -> Resources
3131 (++) [] ys = ys
3232 (++) (x :: xs) ys = x :: xs ++ ys
3333
3434{- Proof that a label has a particular type in a given context -}
3535public export
36−data InState : lbl -> Type -> Context -> Type where
36+data InState : lbl -> Type -> Resources -> Type where
3737 Here : InState lbl st (MkRes lbl st :: rs)
3838 There : InState lbl st rs -> InState lbl st (r :: rs)
3939
4040{- Update an entry in a context with a new state -}
4141public export
42−updateCtxt : (ctxt : Context) ->
43− InState lbl st ctxt -> Type -> Context
42+updateCtxt : (ctxt : Resources) ->
43+ InState lbl st ctxt -> Type -> Resources
4444updateCtxt (MkRes lbl _ :: rs) Here val = (MkRes lbl val :: rs)
4545updateCtxt (r :: rs) (There x) ty = r :: updateCtxt rs x ty
4646
4747{- Remove an entry from a context -}
4848public export
49−drop : (ctxt : Context) -> (prf : InState lbl st ctxt) ->
50− Context
49+drop : (ctxt : Resources) -> (prf : InState lbl st ctxt) ->
50+ Resources
5151drop (MkRes lbl st :: rs) Here = rs
5252drop (r :: rs) (There p) = r :: drop rs p
5353
5454{- Proof that a resource state (label/type) is in a context -}
5555public export
56−data ElemCtxt : Resource -> Context -> Type where
56+data ElemCtxt : Resource -> Resources -> Type where
5757 HereCtxt : ElemCtxt a (a :: as)
5858 ThereCtxt : ElemCtxt a as -> ElemCtxt a (b :: as)
5959
6060public export %error_reduce
61−dropEl : (ys: _) -> ElemCtxt x ys -> Context
61+dropEl : (ys: _) -> ElemCtxt x ys -> Resources
6262dropEl (x :: as) HereCtxt = as
6363dropEl (x :: as) (ThereCtxt p) = x :: dropEl as p
6464
6565{- Proof that a variable name is in a context -}
6666public export
67−data VarInCtxt : Var -> Context -> Type where
67+data VarInCtxt : Var -> Resources -> Type where
6868 VarHere : VarInCtxt a (MkRes a st :: as)
6969 VarThere : VarInCtxt a as -> VarInCtxt a (b :: as)
7070
7171public export %error_reduce
72−dropVarIn : (ys: _) -> VarInCtxt x ys -> Context
72+dropVarIn : (ys: _) -> VarInCtxt x ys -> Resources
7373dropVarIn ((MkRes x _) :: as) VarHere = as
7474dropVarIn (x :: as) (VarThere p) = x :: dropVarIn as p
7575
@@ -85,13 +85,13 @@ namespace VarList
8585 (::) : Var -> VarList ts -> VarList (t :: ts)
8686
8787 public export
88− mkCtxt : VarList tys -> Context
88+ mkCtxt : VarList tys -> Resources
8989 mkCtxt [] = []
9090 mkCtxt {tys = (t :: ts)} (v :: vs) = (v ::: t) :: mkCtxt vs
9191
9292{- Proof that a context is a subset of another context -}
9393public export
94−data SubCtxt : Context -> Context -> Type where
94+data SubCtxt : Resources -> Resources -> Type where
9595 SubNil : SubCtxt [] []
9696 Skip : SubCtxt xs ys -> SubCtxt xs (y :: ys)
9797 InCtxt : (el : ElemCtxt x ys) -> SubCtxt xs (dropEl ys el) ->
@@ -110,7 +110,7 @@ subCtxtNil {xs = (x :: xs)} = Skip subCtxtNil
110110
111111{- Proof that every variable in the list appears once in the context -}
112112public export
113−data VarsIn : List Var -> Context -> Type where
113+data VarsIn : List Var -> Resources -> Type where
114114 VarsNil : VarsIn [] []
115115 SkipVar : VarsIn xs ys -> VarsIn xs (y :: ys)
116116 InCtxtVar : (el : VarInCtxt x ys) -> VarsIn xs (dropVarIn ys el) ->
@@ -122,8 +122,8 @@ Uninhabited (ElemCtxt x []) where
122122 uninhabited (ThereCtxt _) impossible
123123
124124public export %error_reduce
125−updateWith : (new : Context) -> (xs : Context) ->
126− SubCtxt ys xs -> Context
125+updateWith : (new : Resources) -> (xs : Resources) ->
126+ SubCtxt ys xs -> Resources
127127-- At the end, add the ones which were updated by the subctxt
128128updateWith new [] SubNil = new
129129updateWith new [] (InCtxt el z) = absurd el
@@ -136,7 +136,7 @@ updateWith (n :: ns) (x :: xs) (InCtxt el p)
136136updateWith new (x :: xs) (Skip p) = x :: updateWith new xs p
137137
138138public export
139−getVarType : (xs : Context) -> VarInCtxt v xs -> Type
139+getVarType : (xs : Resources) -> VarInCtxt v xs -> Type
140140getVarType ((MkRes v st) :: as) VarHere = st
141141getVarType (b :: as) (VarThere x) = getVarType as x
142142
@@ -147,20 +147,20 @@ getCombineType (InCtxtVar el y) = getVarType _ el :: getCombineType y
147147getCombineType (SkipVar x) = getCombineType x
148148
149149public export
150−dropCombined : VarsIn vs ctxt -> Context
150+dropCombined : VarsIn vs ctxt -> Resources
151151dropCombined {ctxt = []} VarsNil = []
152152dropCombined {ctxt} (InCtxtVar el y) = dropCombined y
153153dropCombined {ctxt = (y :: ys)} (SkipVar x) = y :: dropCombined x
154154
155155public export
156−combineVarsIn : (ctxt : Context) -> VarsIn (comp :: vs) ctxt -> Context
156+combineVarsIn : (ctxt : Resources) -> VarsIn (comp :: vs) ctxt -> Resources
157157combineVarsIn {comp} ctxt (InCtxtVar el x)
158158 = ((comp ::: Composite (getCombineType x)) :: dropCombined (InCtxtVar el x))
159159combineVarsIn (y :: ys) (SkipVar x) = y :: combineVarsIn ys x
160160
161161namespace Env
162162 public export
163− data Env : Context -> Type where
163+ data Env : Resources -> Type where
164164 Nil : Env []
165165 (::) : ty -> Env xs -> Env ((lbl ::: ty) :: xs)
166166
@@ -224,7 +224,7 @@ data Action : Type -> Type where
224224 Stable : lbl -> Type -> Action ty
225225 Trans : lbl -> Type -> (ty -> Type) -> Action ty
226226 Remove : lbl -> Type -> Action ty
227− Add : (ty -> Context) -> Action ty
227+ Add : (ty -> Resources) -> Action ty
228228
229229namespace Stable
230230 public export %error_reduce
@@ -264,7 +264,7 @@ addIfJust : Type -> Action (Maybe a)
264264addIfJust ty = Add (maybe [] (\var => [var ::: ty]))
265265
266266public export
267−kept : SubCtxt xs ys -> Context
267+kept : SubCtxt xs ys -> Resources
268268kept SubNil = []
269269kept (InCtxt el p) = kept p
270270kept (Skip {y} p) = y :: kept p
@@ -279,7 +279,7 @@ data State : Type -> Type where
279279export
280280data STrans : (m : Type -> Type) ->
281281 (ty : Type) ->
282− Context -> (ty -> Context) ->
282+ Resources -> (ty -> Resources) ->
283283 Type where
284284 Pure : (result : ty) ->
285285 STrans m ty (out_fn result) out_fn
@@ -326,7 +326,7 @@ data STrans : (m : Type -> Type) ->
326326namespace Loop
327327 export
328328 data STransLoop : (m : Type -> Type) -> (ty : Type) ->
329− Context -> (ty -> Context) -> Type where
329+ Resources -> (ty -> Resources) -> Type where
330330 Bind : STrans m a st1 st2_fn ->
331331 ((result : a) -> Inf (STransLoop m b (st2_fn result) st3_fn)) ->
332332 STransLoop m b st1 st3_fn
@@ -495,7 +495,7 @@ namespace Loop
495495 pure = Pure
496496
497497public export %error_reduce
498−out_res : ty -> (as : List (Action ty)) -> Context
498+out_res : ty -> (as : List (Action ty)) -> Resources
499499out_res x [] = []
500500out_res x ((Stable lbl inr) :: xs) = (lbl ::: inr) :: out_res x xs
501501out_res x ((Trans lbl inr outr) :: xs)
@@ -504,7 +504,7 @@ out_res x ((Remove lbl inr) :: xs) = out_res x xs
504504out_res x (Add outf :: xs) = outf x ++ out_res x xs
505505
506506public export %error_reduce
507−in_res : (as : List (Action ty)) -> Context
507+in_res : (as : List (Action ty)) -> Resources
508508in_res [] = []
509509in_res ((Stable lbl inr) :: xs) = (lbl ::: inr) :: in_res xs
510510in_res ((Trans lbl inr outr) :: xs) = (lbl ::: inr) :: in_res xs