make (//) lazier

This commit is contained in:
rhiannon morris 2021-09-09 23:54:18 +02:00
parent b29c56e0ae
commit 8c675d01d5
2 changed files with 13 additions and 11 deletions

View File

@ -35,7 +35,7 @@ export Ord (f to) => Ord (Subst f from to) where compare = compare `on` repr
infixl 8 //
public export
interface FromVar env => CanSubst env term where
(//) : term from -> Subst env from to -> term to
(//) : term from -> Lazy (Subst env from to) -> term to
public export
CanSubst1 : (Nat -> Type) -> Type

View File

@ -187,11 +187,12 @@ export FromVar (Term d) where fromVar = E . fromVar
||| - otherwise, wraps in a new closure
export
CanSubst (Elim d) (Elim d) where
F x // _ = F x
B i // th = th !! i
CloE e ph // th = CloE e $ assert_total $ ph . th
e // Shift SZ = e
e // th = CloE e th
F x // _ = F x
B i // th = th !! i
CloE e ph // th = assert_total CloE e $ ph . th
e // th = case force th of
Shift SZ => e
th => CloE e th
||| does the minimal reasonable work:
||| - deletes the closure around an atomic constant like `TYPE`
@ -201,11 +202,12 @@ CanSubst (Elim d) (Elim d) where
||| - otherwise, wraps in a new closure
export
CanSubst (Elim d) (Term d) where
TYPE l // _ = TYPE l
E e // th = E $ e // th
CloT s ph // th = CloT s $ ph . th
s // Shift SZ = s
s // th = CloT s th
TYPE l // _ = TYPE l
E e // th = E $ e // th
CloT s ph // th = CloT s $ ph . th
s // th = case force th of
Shift SZ => s
th => CloT s th
export CanShift (Term d) where i // by = i // Shift by {env=(Elim d)}
export CanShift (Elim d) where i // by = i // Shift by {env=(Elim d)}