replace Context.tabulate with tabulateVar
- takes a function `Var n -> a` - results are no longer backwards lmao
This commit is contained in:
parent
e880b7165a
commit
722c05225d
4 changed files with 49 additions and 26 deletions
|
@ -109,21 +109,18 @@ fromSnocVect [<] = [<]
|
|||
fromSnocVect (sx :< x) = fromSnocVect sx :< x
|
||||
|
||||
|
||||
public export
|
||||
tabulateLT : (n : Nat) -> ((i : Nat) -> (0 p : i `LT` n) => tm i) ->
|
||||
Context tm n
|
||||
tabulateLT 0 f = [<]
|
||||
tabulateLT (S k) f =
|
||||
tabulateLT k (\i => f i @{lteSuccRight %search}) :< f k @{reflexive}
|
||||
export
|
||||
tabulateVar : (n : Nat) -> (Var n -> a) -> Context' a n
|
||||
tabulateVar 0 f = [<]
|
||||
tabulateVar (S k) f = tabulateVar k (f . VS) :< f VZ
|
||||
|
||||
public export
|
||||
tabulate : ((n : Nat) -> tm n) -> (n : Nat) -> Context tm n
|
||||
tabulate f n = tabulateLT n (\i => f i)
|
||||
-- [todo] fixup argument order lol
|
||||
export
|
||||
allVars : (n : Nat) -> Context' (Var n) n
|
||||
allVars n = tabulateVar n id
|
||||
|
||||
public export
|
||||
replicate : (n : Nat) -> a -> Context' a n
|
||||
replicate n x = tabulate (const x) n
|
||||
replicate n x = tabulateVar n $ const x
|
||||
|
||||
|
||||
public export
|
||||
|
|
|
@ -62,7 +62,7 @@ export %inline [AndM] {n : Nat} -> Monoid (FreeVars n) where neutral = all
|
|||
|
||||
private
|
||||
self : {n : Nat} -> Context' (FreeVars n) n
|
||||
self = tabulate (\i => FV $ tabulate (== i) n) n
|
||||
self = tabulateVar n $ \i => FV $ tabulateVar n (== i)
|
||||
|
||||
export
|
||||
shift : forall from, to. Shift from to -> FreeVars from -> FreeVars to
|
||||
|
@ -74,13 +74,12 @@ shift by (FV xs) = FV $ shift' by xs where
|
|||
|
||||
export
|
||||
fromSet : {n : Nat} -> SortedSet (Var n) -> FreeVars n
|
||||
fromSet vs = FV $ tabulateLT n $ \i => contains (V i) vs
|
||||
fromSet vs = FV $ tabulateVar n $ \i => contains i vs
|
||||
|
||||
export
|
||||
toSet : {n : Nat} -> FreeVars n -> SortedSet (Var n)
|
||||
toSet (FV vs) =
|
||||
foldl_ (\s, i => maybe s (\i => insert i s) i) empty $
|
||||
zipWith (\i, b => guard b $> i) (tabulateLT n V) vs
|
||||
toSet (FV vs) = SortedSet.fromList $ fold $
|
||||
Context.zipWith (\i, b => i <$ guard b) (allVars n) vs
|
||||
|
||||
|
||||
public export
|
||||
|
@ -230,7 +229,7 @@ HasFreeVars (Elim d) where
|
|||
|
||||
private
|
||||
expandDShift : {d1 : Nat} -> Shift d1 d2 -> Loc -> Context' (Dim d2) d1
|
||||
expandDShift by loc = tabulateLT d1 (\i => BV i loc // by)
|
||||
expandDShift by loc = tabulateVar d1 (\i => B i loc // by)
|
||||
|
||||
private
|
||||
expandDSubst : {d1 : Nat} -> DSubst d1 d2 -> Loc -> Context' (Dim d2) d1
|
||||
|
|
|
@ -144,15 +144,7 @@ interface FromVar f where %inline fromVar : Var n -> Loc -> f n
|
|||
|
||||
public export FromVar Var where fromVar x _ = x
|
||||
|
||||
export
|
||||
tabulateV : {0 tm : Nat -> Type} -> (forall n. Var n -> tm n) ->
|
||||
(n : Nat) -> Vect n (tm n)
|
||||
tabulateV f 0 = []
|
||||
tabulateV f (S n) = f VZ :: tabulateV (f . VS) n
|
||||
|
||||
export
|
||||
allVars : (n : Nat) -> Vect n (Var n)
|
||||
allVars n = tabulateV id n
|
||||
|
||||
|
||||
public export
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue