2022-04-23 18:21:30 -04:00
|
|
|
|
module Quox.Syntax.Term.Base
|
|
|
|
|
|
2023-09-20 15:56:59 -04:00
|
|
|
|
import public Quox.Var
|
2023-09-20 15:58:04 -04:00
|
|
|
|
import public Quox.Scoped
|
2022-04-23 18:21:30 -04:00
|
|
|
|
import public Quox.Syntax.Shift
|
|
|
|
|
import public Quox.Syntax.Subst
|
|
|
|
|
import public Quox.Syntax.Qty
|
|
|
|
|
import public Quox.Syntax.Dim
|
2023-04-15 09:13:01 -04:00
|
|
|
|
import public Quox.Syntax.Term.TyConKind
|
2022-04-23 18:21:30 -04:00
|
|
|
|
import public Quox.Name
|
2023-05-01 21:06:25 -04:00
|
|
|
|
import public Quox.Loc
|
2023-03-16 13:18:49 -04:00
|
|
|
|
import public Quox.Context
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
import Quox.Pretty
|
|
|
|
|
|
|
|
|
|
import public Data.DPair
|
|
|
|
|
import Data.List
|
|
|
|
|
import Data.Maybe
|
|
|
|
|
import Data.Nat
|
|
|
|
|
import public Data.So
|
|
|
|
|
import Data.String
|
2023-02-22 01:45:10 -05:00
|
|
|
|
import public Data.SortedMap
|
2023-04-15 09:13:01 -04:00
|
|
|
|
import public Data.SortedMap.Dependent
|
2023-02-22 01:45:10 -05:00
|
|
|
|
import public Data.SortedSet
|
2023-04-27 15:37:20 -04:00
|
|
|
|
import Derive.Prelude
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
%default total
|
2023-04-27 15:37:20 -04:00
|
|
|
|
%language ElabReflection
|
|
|
|
|
|
|
|
|
|
%hide TT.Name
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
|
2023-01-22 18:53:34 -05:00
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
TermLike : Type
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TermLike = (q, d, n : Nat) -> Type
|
2023-01-22 18:53:34 -05:00
|
|
|
|
|
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
TSubstLike : Type
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TSubstLike = (q, d, n1, n2 : Nat) -> Type
|
2023-01-22 18:53:34 -05:00
|
|
|
|
|
2023-03-05 10:48:29 -05:00
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
Universe : Type
|
2023-03-05 10:48:29 -05:00
|
|
|
|
Universe = Nat
|
|
|
|
|
|
2023-02-22 01:45:10 -05:00
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
TagVal : Type
|
2023-02-22 01:45:10 -05:00
|
|
|
|
TagVal = String
|
2023-01-22 18:53:34 -05:00
|
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
|
|
2022-04-23 18:21:30 -04:00
|
|
|
|
mutual
|
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
TSubst : TSubstLike
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TSubst q d = Subst $ \n => Elim q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-04-01 13:16:43 -04:00
|
|
|
|
||| first argument `d` is dimension scope size;
|
|
|
|
|
||| second `n` is term scope size
|
2022-04-23 18:21:30 -04:00
|
|
|
|
public export
|
2024-05-27 15:28:22 -04:00
|
|
|
|
data Term : (q, d, n : Nat) -> Type where
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| type of types
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TYPE : (l : Universe) -> (loc : Loc) -> Term q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-11-01 10:17:15 -04:00
|
|
|
|
||| IO state token. this is a builtin because otherwise #[main] being a
|
|
|
|
|
||| builtin makes no sense
|
2024-05-27 15:28:22 -04:00
|
|
|
|
IOState : (loc : Loc) -> Term q d n
|
2023-11-01 10:17:15 -04:00
|
|
|
|
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| function type
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Pi : (qty : Qty q) -> (arg : Term q d n) ->
|
|
|
|
|
(res : ScopeTerm q d n) -> (loc : Loc) -> Term q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| function term
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Lam : (body : ScopeTerm q d n) -> (loc : Loc) -> Term q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-01-26 13:54:46 -05:00
|
|
|
|
||| pair type
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Sig : (fst : Term q d n) -> (snd : ScopeTerm q d n) -> (loc : Loc) ->
|
|
|
|
|
Term q d n
|
2023-01-26 13:54:46 -05:00
|
|
|
|
||| pair value
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Pair : (fst, snd : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-01-26 13:54:46 -05:00
|
|
|
|
|
2023-02-22 01:45:10 -05:00
|
|
|
|
||| enumeration type
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Enum : (cases : SortedSet TagVal) -> (loc : Loc) -> Term q d n
|
2023-02-22 01:45:10 -05:00
|
|
|
|
||| enumeration value
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Tag : (tag : TagVal) -> (loc : Loc) -> Term q d n
|
2023-02-22 01:45:10 -05:00
|
|
|
|
|
2023-01-20 20:34:28 -05:00
|
|
|
|
||| equality type
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Eq : (ty : DScopeTerm q d n) -> (l, r : Term q d n) -> (loc : Loc) ->
|
|
|
|
|
Term q d n
|
2023-01-20 20:34:28 -05:00
|
|
|
|
||| equality term
|
2024-05-27 15:28:22 -04:00
|
|
|
|
DLam : (body : DScopeTerm q d n) -> (loc : Loc) -> Term q d n
|
2023-01-20 20:34:28 -05:00
|
|
|
|
|
2023-03-26 08:40:54 -04:00
|
|
|
|
||| natural numbers (temporary until 𝐖 gets added)
|
2024-05-27 15:28:22 -04:00
|
|
|
|
NAT : (loc : Loc) -> Term q d n
|
|
|
|
|
Nat : (val : Nat) -> (loc : Loc) -> Term q d n
|
|
|
|
|
Succ : (p : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-03-26 08:40:54 -04:00
|
|
|
|
|
2023-11-01 10:17:15 -04:00
|
|
|
|
||| strings
|
2024-05-27 15:28:22 -04:00
|
|
|
|
STRING : (loc : Loc) -> Term q d n
|
|
|
|
|
Str : (str : String) -> (loc : Loc) -> Term q d n
|
2023-11-01 10:17:15 -04:00
|
|
|
|
|
2023-03-31 13:11:35 -04:00
|
|
|
|
||| "box" (package a value up with a certain quantity)
|
2024-05-27 15:28:22 -04:00
|
|
|
|
BOX : (qty : Qty q) -> (ty : Term q d n) -> (loc : Loc) -> Term q d n
|
|
|
|
|
Box : (val : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-03-31 13:11:35 -04:00
|
|
|
|
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Let : (qty : Qty q) -> (rhs : Elim q d n) ->
|
|
|
|
|
(body : ScopeTerm q d n) -> (loc : Loc) -> Term q d n
|
2023-12-04 16:47:52 -05:00
|
|
|
|
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| elimination
|
2024-05-27 15:28:22 -04:00
|
|
|
|
E : (e : Elim q d n) -> Term q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
||| term closure/suspended substitution
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CloT : WithSubst (Term q d) (Elim q d) n -> Term q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| dimension closure/suspended substitution
|
2024-05-27 15:28:22 -04:00
|
|
|
|
DCloT : WithSubst (\d => Term q d n) Dim d -> Term q d n
|
|
|
|
|
||| quantity closure/suspended substitution
|
|
|
|
|
QCloT : WithSubstR (\q => Term q d n) Qty q -> Term q d n
|
2023-04-27 15:37:20 -04:00
|
|
|
|
%name Term s, t, r
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
||| first argument `d` is dimension scope size, second `n` is term scope size
|
|
|
|
|
public export
|
2024-05-27 15:28:22 -04:00
|
|
|
|
data Elim : (q, d, n : Nat) -> Type where
|
2023-05-21 14:09:34 -04:00
|
|
|
|
||| free variable, possibly with a displacement (see @crude, or @mugen for a
|
|
|
|
|
||| more abstract and formalised take)
|
|
|
|
|
|||
|
|
|
|
|
||| e.g. if f : ★₀ → ★₁, then f¹ : ★₁ → ★₂
|
2024-05-27 15:28:22 -04:00
|
|
|
|
F : (x : Name) -> (u : Universe) -> (loc : Loc) -> Elim q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| bound variable
|
2024-05-27 15:28:22 -04:00
|
|
|
|
B : (i : Var n) -> (loc : Loc) -> Elim q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
||| term application
|
2024-05-27 15:28:22 -04:00
|
|
|
|
App : (fun : Elim q d n) -> (arg : Term q d n) -> (loc : Loc) -> Elim q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-01-26 13:54:46 -05:00
|
|
|
|
||| pair destruction
|
|
|
|
|
|||
|
2023-02-22 01:40:19 -05:00
|
|
|
|
||| `CasePair 𝜋 𝑒 ([𝑟], 𝐴) ([𝑥, 𝑦], 𝑡)` is
|
2023-03-04 15:02:51 -05:00
|
|
|
|
||| `𝐜𝐚𝐬𝐞 𝜋 · 𝑒 𝐫𝐞𝐭𝐮𝐫𝐧 𝑟 ⇒ 𝐴 𝐨𝐟 { (𝑥, 𝑦) ⇒ 𝑡 }`
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CasePair : (qty : Qty q) -> (pair : Elim q d n) ->
|
|
|
|
|
(ret : ScopeTerm q d n) ->
|
|
|
|
|
(body : ScopeTermN 2 q d n) ->
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(loc : Loc) ->
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Elim q d n
|
2023-01-26 13:54:46 -05:00
|
|
|
|
|
2023-09-18 15:52:51 -04:00
|
|
|
|
||| first element of a pair. only works in non-linear contexts.
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Fst : (pair : Elim q d n) -> (loc : Loc) -> Elim q d n
|
2023-09-18 15:52:51 -04:00
|
|
|
|
|
|
|
|
|
||| second element of a pair. only works in non-linear contexts.
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Snd : (pair : Elim q d n) -> (loc : Loc) -> Elim q d n
|
2023-09-18 15:52:51 -04:00
|
|
|
|
|
2023-02-22 01:45:10 -05:00
|
|
|
|
||| enum matching
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CaseEnum : (qty : Qty q) -> (tag : Elim q d n) ->
|
|
|
|
|
(ret : ScopeTerm q d n) ->
|
|
|
|
|
(arms : CaseEnumArms q d n) ->
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(loc : Loc) ->
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Elim q d n
|
2023-03-26 08:40:54 -04:00
|
|
|
|
|
|
|
|
|
||| nat matching
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CaseNat : (qty, qtyIH : Qty q) -> (nat : Elim q d n) ->
|
|
|
|
|
(ret : ScopeTerm q d n) ->
|
|
|
|
|
(zero : Term q d n) ->
|
|
|
|
|
(succ : ScopeTermN 2 q d n) ->
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(loc : Loc) ->
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Elim q d n
|
2023-02-22 01:45:10 -05:00
|
|
|
|
|
2023-03-31 13:11:35 -04:00
|
|
|
|
||| unboxing
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CaseBox : (qty : Qty q) -> (box : Elim q d n) ->
|
|
|
|
|
(ret : ScopeTerm q d n) ->
|
|
|
|
|
(body : ScopeTerm q d n) ->
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(loc : Loc) ->
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Elim q d n
|
2023-03-31 13:11:35 -04:00
|
|
|
|
|
2023-01-20 20:34:28 -05:00
|
|
|
|
||| dim application
|
2024-05-27 15:28:22 -04:00
|
|
|
|
DApp : (fun : Elim q d n) -> (arg : Dim d) -> (loc : Loc) -> Elim q d n
|
2023-01-20 20:34:28 -05:00
|
|
|
|
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| type-annotated term
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Ann : (tm, ty : Term q d n) -> (loc : Loc) -> Elim q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
|
||| coerce a value along a type equality, or show its coherence
|
|
|
|
|
||| [@xtt; §2.1.1]
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Coe : (ty : DScopeTerm q d n) -> (p, p' : Dim d) ->
|
|
|
|
|
(val : Term q d n) -> (loc : Loc) -> Elim q d n
|
2023-04-15 09:13:01 -04:00
|
|
|
|
|
|
|
|
|
||| "generalised composition" [@xtt; §2.1.2]
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Comp : (ty : Term q d n) -> (p, p' : Dim d) ->
|
|
|
|
|
(val : Term q d n) -> (r : Dim d) ->
|
|
|
|
|
(zero, one : DScopeTerm q d n) -> (loc : Loc) -> Elim q d n
|
2023-04-15 09:13:01 -04:00
|
|
|
|
|
|
|
|
|
||| match on types. needed for b.s. of coercions [@xtt; §2.2]
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TypeCase : (ty : Elim q d n) -> (ret : Term q d n) ->
|
|
|
|
|
(arms : TypeCaseArms q d n) -> (def : Term q d n) ->
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(loc : Loc) ->
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Elim q d n
|
2023-04-03 11:46:23 -04:00
|
|
|
|
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| term closure/suspended substitution
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CloE : WithSubst (Elim q d) (Elim q d) n -> Elim q d n
|
2022-04-23 18:21:30 -04:00
|
|
|
|
||| dimension closure/suspended substitution
|
2024-05-27 15:28:22 -04:00
|
|
|
|
DCloE : WithSubst (\d => Elim q d n) Dim d -> Elim q d n
|
|
|
|
|
||| quantity closure/suspended substitution
|
|
|
|
|
QCloE : WithSubstR (\q => Elim q d n) Qty q -> Elim q d n
|
2023-04-27 15:37:20 -04:00
|
|
|
|
%name Elim e, f
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
CaseEnumArms : TermLike
|
2024-05-27 15:28:22 -04:00
|
|
|
|
CaseEnumArms q d n = SortedMap TagVal (Term q d n)
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
|
public export
|
|
|
|
|
TypeCaseArms : TermLike
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TypeCaseArms q d n = SortedDMap TyConKind (\k => TypeCaseArmBody k q d n)
|
2023-04-15 09:13:01 -04:00
|
|
|
|
|
|
|
|
|
public export
|
|
|
|
|
TypeCaseArm : TermLike
|
2024-05-27 15:28:22 -04:00
|
|
|
|
TypeCaseArm q d n = (k ** TypeCaseArmBody k q d n)
|
2023-04-15 09:13:01 -04:00
|
|
|
|
|
|
|
|
|
public export
|
|
|
|
|
TypeCaseArmBody : TyConKind -> TermLike
|
|
|
|
|
TypeCaseArmBody k = ScopeTermN (arity k)
|
|
|
|
|
|
|
|
|
|
|
2023-01-22 21:22:50 -05:00
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
ScopeTermN, DScopeTermN : Nat -> TermLike
|
2024-05-27 15:28:22 -04:00
|
|
|
|
ScopeTermN s q d n = Scoped s (Term q d) n
|
|
|
|
|
DScopeTermN s q d n = Scoped s (\d => Term q d n) d
|
2023-02-22 01:40:19 -05:00
|
|
|
|
|
|
|
|
|
public export
|
2023-04-15 09:13:01 -04:00
|
|
|
|
ScopeTerm, DScopeTerm : TermLike
|
2023-02-22 01:40:19 -05:00
|
|
|
|
ScopeTerm = ScopeTermN 1
|
2023-01-22 21:22:50 -05:00
|
|
|
|
DScopeTerm = DScopeTermN 1
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2024-05-27 15:28:22 -04:00
|
|
|
|
export %hint EqTerm : Eq (Term q d n)
|
|
|
|
|
export %hint EqElim : Eq (Elim q d n)
|
|
|
|
|
EqTerm = assert_total {a = Eq (Term q d n)} deriveEq
|
|
|
|
|
EqElim = assert_total {a = Eq (Elim q d n)} deriveEq
|
2023-04-27 15:37:20 -04:00
|
|
|
|
|
2024-05-27 15:28:22 -04:00
|
|
|
|
-- export %hint ShowTerm : {q, d, n : Nat} -> Show (Term q d n)
|
|
|
|
|
-- export %hint ShowElim : {q, d, n : Nat} -> Show (Elim q d n)
|
|
|
|
|
-- ShowTerm = assert_total {a = Show (Term q d n)} deriveShow
|
|
|
|
|
-- ShowElim = assert_total {a = Show (Elim q d n)} deriveShow
|
2022-04-23 18:21:30 -04:00
|
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
|
|
|
|
|
|
export
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Located (Elim q d n) where
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(F _ _ loc).loc = loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(B _ loc).loc = loc
|
|
|
|
|
(App _ _ loc).loc = loc
|
|
|
|
|
(CasePair _ _ _ _ loc).loc = loc
|
2023-09-18 15:52:51 -04:00
|
|
|
|
(Fst _ loc).loc = loc
|
|
|
|
|
(Snd _ loc).loc = loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
(CaseEnum _ _ _ _ loc).loc = loc
|
|
|
|
|
(CaseNat _ _ _ _ _ _ loc).loc = loc
|
|
|
|
|
(CaseBox _ _ _ _ loc).loc = loc
|
|
|
|
|
(DApp _ _ loc).loc = loc
|
|
|
|
|
(Ann _ _ loc).loc = loc
|
|
|
|
|
(Coe _ _ _ _ loc).loc = loc
|
|
|
|
|
(Comp _ _ _ _ _ _ _ loc).loc = loc
|
|
|
|
|
(TypeCase _ _ _ _ loc).loc = loc
|
|
|
|
|
(CloE (Sub e _)).loc = e.loc
|
|
|
|
|
(DCloE (Sub e _)).loc = e.loc
|
2024-05-27 15:28:22 -04:00
|
|
|
|
(QCloE (SubR e _)).loc = e.loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
|
|
|
|
|
export
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Located (Term q d n) where
|
|
|
|
|
(TYPE _ loc).loc = loc
|
|
|
|
|
(IOState loc).loc = loc
|
|
|
|
|
(Pi _ _ _ loc).loc = loc
|
|
|
|
|
(Lam _ loc).loc = loc
|
|
|
|
|
(Sig _ _ loc).loc = loc
|
|
|
|
|
(Pair _ _ loc).loc = loc
|
|
|
|
|
(Enum _ loc).loc = loc
|
|
|
|
|
(Tag _ loc).loc = loc
|
|
|
|
|
(Eq _ _ _ loc).loc = loc
|
|
|
|
|
(DLam _ loc).loc = loc
|
|
|
|
|
(NAT loc).loc = loc
|
|
|
|
|
(Nat _ loc).loc = loc
|
|
|
|
|
(STRING loc).loc = loc
|
|
|
|
|
(Str _ loc).loc = loc
|
|
|
|
|
(Succ _ loc).loc = loc
|
|
|
|
|
(BOX _ _ loc).loc = loc
|
|
|
|
|
(Box _ loc).loc = loc
|
|
|
|
|
(Let _ _ _ loc).loc = loc
|
|
|
|
|
(E e).loc = e.loc
|
|
|
|
|
(CloT (Sub t _)).loc = t.loc
|
|
|
|
|
(DCloT (Sub t _)).loc = t.loc
|
|
|
|
|
(QCloT (SubR t _)).loc = t.loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
Located1 f => Located (ScopedBody s f n) where
|
|
|
|
|
(Y t).loc = t.loc
|
|
|
|
|
(N t).loc = t.loc
|
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
Located1 f => Located (Scoped s f n) where
|
|
|
|
|
t.loc = t.body.loc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Relocatable (Elim q d n) where
|
2023-05-21 14:09:34 -04:00
|
|
|
|
setLoc loc (F x u _) = F x u loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (B i _) = B i loc
|
|
|
|
|
setLoc loc (App fun arg _) = App fun arg loc
|
|
|
|
|
setLoc loc (CasePair qty pair ret body _) =
|
|
|
|
|
CasePair qty pair ret body loc
|
2023-09-18 15:52:51 -04:00
|
|
|
|
setLoc loc (Fst pair _) = Fst pair loc
|
|
|
|
|
setLoc loc (Snd pair _) = Fst pair loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (CaseEnum qty tag ret arms _) =
|
|
|
|
|
CaseEnum qty tag ret arms loc
|
|
|
|
|
setLoc loc (CaseNat qty qtyIH nat ret zero succ _) =
|
|
|
|
|
CaseNat qty qtyIH nat ret zero succ loc
|
|
|
|
|
setLoc loc (CaseBox qty box ret body _) =
|
|
|
|
|
CaseBox qty box ret body loc
|
|
|
|
|
setLoc loc (DApp fun arg _) =
|
|
|
|
|
DApp fun arg loc
|
|
|
|
|
setLoc loc (Ann tm ty _) =
|
|
|
|
|
Ann tm ty loc
|
|
|
|
|
setLoc loc (Coe ty p q val _) =
|
|
|
|
|
Coe ty p q val loc
|
|
|
|
|
setLoc loc (Comp ty p q val r zero one _) =
|
|
|
|
|
Comp ty p q val r zero one loc
|
|
|
|
|
setLoc loc (TypeCase ty ret arms def _) =
|
|
|
|
|
TypeCase ty ret arms def loc
|
|
|
|
|
setLoc loc (CloE (Sub term subst)) =
|
|
|
|
|
CloE $ Sub (setLoc loc term) subst
|
|
|
|
|
setLoc loc (DCloE (Sub term subst)) =
|
|
|
|
|
DCloE $ Sub (setLoc loc term) subst
|
2024-05-27 15:28:22 -04:00
|
|
|
|
setLoc loc (QCloE (SubR term subst)) =
|
|
|
|
|
QCloE $ SubR (setLoc loc term) subst
|
2023-05-01 21:06:25 -04:00
|
|
|
|
|
|
|
|
|
export
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Relocatable (Term q d n) where
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (TYPE l _) = TYPE l loc
|
2023-11-01 10:17:15 -04:00
|
|
|
|
setLoc loc (IOState _) = IOState loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (Pi qty arg res _) = Pi qty arg res loc
|
|
|
|
|
setLoc loc (Lam body _) = Lam body loc
|
|
|
|
|
setLoc loc (Sig fst snd _) = Sig fst snd loc
|
|
|
|
|
setLoc loc (Pair fst snd _) = Pair fst snd loc
|
|
|
|
|
setLoc loc (Enum cases _) = Enum cases loc
|
|
|
|
|
setLoc loc (Tag tag _) = Tag tag loc
|
|
|
|
|
setLoc loc (Eq ty l r _) = Eq ty l r loc
|
|
|
|
|
setLoc loc (DLam body _) = DLam body loc
|
2023-11-02 13:14:22 -04:00
|
|
|
|
setLoc loc (NAT _) = NAT loc
|
2023-11-02 15:01:34 -04:00
|
|
|
|
setLoc loc (Nat n _) = Nat n loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (Succ p _) = Succ p loc
|
2023-11-01 10:17:15 -04:00
|
|
|
|
setLoc loc (STRING _) = STRING loc
|
|
|
|
|
setLoc loc (Str s _) = Str s loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (BOX qty ty _) = BOX qty ty loc
|
|
|
|
|
setLoc loc (Box val _) = Box val loc
|
2023-12-04 16:47:52 -05:00
|
|
|
|
setLoc loc (Let qty rhs body _) = Let qty rhs body loc
|
2023-05-01 21:06:25 -04:00
|
|
|
|
setLoc loc (E e) = E $ setLoc loc e
|
|
|
|
|
setLoc loc (CloT (Sub term subst)) = CloT $ Sub (setLoc loc term) subst
|
|
|
|
|
setLoc loc (DCloT (Sub term subst)) = DCloT $ Sub (setLoc loc term) subst
|
2024-05-27 15:28:22 -04:00
|
|
|
|
setLoc loc (QCloT (SubR term subst)) = QCloT $ SubR (setLoc loc term) subst
|
2023-05-01 21:06:25 -04:00
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
Relocatable1 f => Relocatable (ScopedBody s f n) where
|
|
|
|
|
setLoc loc (Y body) = Y $ setLoc loc body
|
|
|
|
|
setLoc loc (N body) = N $ setLoc loc body
|
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
Relocatable1 f => Relocatable (Scoped s f n) where
|
|
|
|
|
setLoc loc (S names body) = S (setLoc loc <$> names) (setLoc loc body)
|
2023-11-27 15:01:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||| more convenient Pi
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
PiY : (qty : Qty q) -> (x : BindName) ->
|
|
|
|
|
(arg : Term q d n) -> (res : Term q d (S n)) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
PiY {qty, x, arg, res, loc} = Pi {qty, arg, res = SY [< x] res, loc}
|
|
|
|
|
|
|
|
|
|
||| more convenient Lam
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
LamY : (x : BindName) -> (body : Term q d (S n)) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
LamY {x, body, loc} = Lam {body = SY [< x] body, loc}
|
|
|
|
|
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
LamN : (body : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
LamN {body, loc} = Lam {body = SN body, loc}
|
|
|
|
|
|
|
|
|
|
||| non dependent function type
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Arr : (qty : Qty q) -> (arg, res : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
Arr {qty, arg, res, loc} = Pi {qty, arg, res = SN res, loc}
|
|
|
|
|
|
|
|
|
|
||| more convenient Sig
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
SigY : (x : BindName) -> (fst : Term q d n) ->
|
|
|
|
|
(snd : Term q d (S n)) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
SigY {x, fst, snd, loc} = Sig {fst, snd = SY [< x] snd, loc}
|
|
|
|
|
|
|
|
|
|
||| non dependent pair type
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
And : (fst, snd : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
And {fst, snd, loc} = Sig {fst, snd = SN snd, loc}
|
|
|
|
|
|
|
|
|
|
||| more convenient Eq
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
EqY : (i : BindName) -> (ty : Term q (S d) n) ->
|
|
|
|
|
(l, r : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
EqY {i, ty, l, r, loc} = Eq {ty = SY [< i] ty, l, r, loc}
|
|
|
|
|
|
|
|
|
|
||| more convenient DLam
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
DLamY : (i : BindName) -> (body : Term q (S d) n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
DLamY {i, body, loc} = DLam {body = SY [< i] body, loc}
|
|
|
|
|
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
DLamN : (body : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
DLamN {body, loc} = DLam {body = SN body, loc}
|
|
|
|
|
|
|
|
|
|
||| non dependent equality type
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Eq0 : (ty, l, r : Term q d n) -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
Eq0 {ty, l, r, loc} = Eq {ty = SN ty, l, r, loc}
|
|
|
|
|
|
|
|
|
|
||| same as `F` but as a term
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
FT : Name -> Universe -> Loc -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
FT x u loc = E $ F x u loc
|
|
|
|
|
|
|
|
|
|
||| same as `B` but as a term
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
BT : Var n -> (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
BT i loc = E $ B i loc
|
|
|
|
|
|
|
|
|
|
||| abbreviation for a bound variable like `BV 4` instead of
|
|
|
|
|
||| `B (VS (VS (VS (VS VZ))))`
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
BV : (i : Nat) -> (0 _ : LT i n) => (loc : Loc) -> Elim q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
BV i loc = B (V i) loc
|
|
|
|
|
|
|
|
|
|
||| same as `BV` but as a term
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
BVT : (i : Nat) -> (0 _ : LT i n) => (loc : Loc) -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
BVT i loc = E $ BV i loc
|
|
|
|
|
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
Zero : Loc -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
Zero = Nat 0
|
|
|
|
|
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
enum : List TagVal -> Loc -> Term q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
enum ts loc = Enum (SortedSet.fromList ts) loc
|
|
|
|
|
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
typeCase : Elim q d n -> Term q d n ->
|
|
|
|
|
List (TypeCaseArm q d n) -> Term q d n -> Loc -> Elim q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
typeCase ty ret arms def loc = TypeCase ty ret (fromList arms) def loc
|
|
|
|
|
|
|
|
|
|
public export %inline
|
2024-05-27 15:28:22 -04:00
|
|
|
|
typeCase1Y : Elim q d n -> Term q d n ->
|
|
|
|
|
(k : TyConKind) -> BContext (arity k) -> Term q d (arity k + n) ->
|
2023-11-27 15:01:36 -05:00
|
|
|
|
(loc : Loc) ->
|
2024-05-27 15:28:22 -04:00
|
|
|
|
{default (NAT loc) def : Term q d n} ->
|
|
|
|
|
Elim q d n
|
2023-11-27 15:01:36 -05:00
|
|
|
|
typeCase1Y ty ret k ns body loc = typeCase ty ret [(k ** SY ns body)] def loc
|