more fromparser stuff

This commit is contained in:
rhiannon morris 2023-03-10 21:52:29 +01:00
parent 426c138c2b
commit d9bc68446f
7 changed files with 130 additions and 31 deletions

View file

@ -176,6 +176,7 @@ data FromPTermError =
| DuplicatesInEnum (List TagVal)
| DimNotInScope Name
| QtyNotGlobal PQty
| DimNameInTerm Name
public export
FromPTerm : (Type -> Type) -> Type
@ -204,6 +205,11 @@ fromPDimWith : FromPTerm m =>
fromPDimWith ds (K e) = pure $ K e
fromPDimWith ds (V i) = fromBaseName (pure . B) (throwError . DimNotInScope) ds i
private
avoidDim : FromPTerm m => Context' BName d -> Name -> m (Term q d n)
avoidDim ds x =
fromName (const $ throwError $ DimNameInTerm x) (pure . FT) ds x
mutual
export
@ -263,7 +269,7 @@ mutual
map E $ (:%) <$> fromPTermElim ds ns s <*> fromPDimWith ds p
V x =>
fromName (pure . E . B) (pure . FT) ns x
fromName (pure . E . B) (avoidDim ds) ns x
s :# a =>
map E $ (:#) <$> fromPTermWith ds ns s <*> fromPTermWith ds ns a
@ -315,9 +321,9 @@ fromPTerm = fromPTermWith [<] [<]
export
globalPQty : FromPTerm m => (q : PQty) -> m (IsGlobal q)
globalPQty Zero = pure GZero
globalPQty One = throwError $ QtyNotGlobal One
globalPQty Any = pure GAny
globalPQty pi = case isGlobal pi of
Yes y => pure y
No n => throwError $ QtyNotGlobal pi
-- [todo] extend substitutions so they can do this injection. that's the sort of

View file

@ -84,6 +84,12 @@ prettyDSubst th =
public export FromVar Dim where fromVar = B
export
inject : Dim d -> Dim (d + inj)
inject (K e) = K e
inject (B i) = B $ inject i
export
CanShift Dim where
K e // _ = K e
@ -127,9 +133,3 @@ DecEq (Dim d) where
public export %inline
BV : (i : Nat) -> (0 _ : LT i d) => Dim d
BV i = B $ V i
export
inject : {0 d' : Nat} -> Dim d -> Dim (d + d')
inject (K e) = K e
inject (B i) = B $ inject i

View file

@ -77,7 +77,7 @@ fromNatWith (S i) (LTESucc p) = VS $ fromNatWith i p
public export %inline
V : (i : Nat) -> {auto 0 p : i `LT` n} -> Var n
V i {p} = fromNatWith i p
V i = fromNatWith i p
export %inline
tryFromNat : Alternative f => (n : Nat) -> Nat -> f (Var n)
@ -112,7 +112,7 @@ toFromNat (S k) (LTESucc x) = cong S $ toFromNat k x
export
inject : Var m -> Var (m + n)
inject : Var m -> Var (m + inj)
inject VZ = VZ
inject (VS i) = VS $ inject i