rewrite Context.(!!)

This commit is contained in:
rhiannon morris 2022-02-27 01:22:02 +01:00
parent 88338050fc
commit 3efff3e96d

View file

@ -66,19 +66,28 @@ tel1 . (tel2 :< s) = (tel1 . tel2) :< s
public export
getShift : CanShift tm => Context tm len -> Var len -> Shift len out -> tm out
getShift (ctx :< t) VZ by = t // drop1 by
getShift (ctx :< t) (VS i) by = getShift ctx i (drop1 by)
getShiftWith : (forall from, to. tm from -> Shift from to -> tm to) ->
Shift len out -> Context tm len -> Var len -> tm out
getShiftWith shft by (ctx :< t) VZ = t `shft` drop1 by
getShiftWith shft by (ctx :< t) (VS i) = getShiftWith shft (drop1 by) ctx i
public export %inline
getShift : CanShift tm => Shift len out -> Context tm len -> Var len -> tm out
getShift = getShiftWith (//)
public export %inline
getWith : (forall from, to. tm from -> Shift from to -> tm to) ->
Context tm len -> Var len -> tm len
getWith shft = getShiftWith shft SZ
infixl 8 !!
public export %inline
(!!) : CanShift tm => Context tm len -> Var len -> tm len
ctx !! i = getShift ctx i SZ
(!!) = getWith (//)
infixl 8 !?
infixl 8 !!!
public export %inline
(!?) : Context' tm len -> Var len -> tm
ctx !? i = (ctx !! i) @{Const}
(!!!) : Context' tm len -> Var len -> tm
(!!!) = getWith const
||| a triangle of bindings. each type binding in a context counts the ues of