2 | module Language.IntrinsicTyping.ABT
4 | import Data.SnocList.Elem
11 | parameters {0 kind : Type}
19 | record Argument where
20 | constructor MkArgument
28 | Signature = List Argument -> kind -> Type
32 | data Term : (sig : Signature) -> (ctx : SnocList kind) -> kind -> Type
36 | data Args : (sig : Signature) -> (ctx : SnocList kind) -> List Argument -> Type
39 | data Term : (sig : Signature) -> (ctx : SnocList kind) -> kind -> Type where
41 | Var : Elem s ctx -> Term sig ctx s
43 | Con : sig args s -> Args sig ctx args -> Term sig ctx s
46 | data Args : (sig : Signature) -> (ctx : SnocList kind) -> List Argument -> Type where
48 | Nil : Args sig ctx []
51 | (::) : {bds : List kind} ->
52 | Term sig (ctx <>< bds) s ->
53 | Args sig ctx args ->
54 | Args sig ctx (MkArgument bds s :: args)
62 | data TY = NAT | ARR TY TY
65 | data SIG : Signature {kind = TY} where
71 | S : SIG [MkArgument [] NAT] NAT
74 | LAM : SIG [MkArgument [s] t] (ARR s t)
77 | APP : SIG [MkArgument [] (ARR s t), MkArgument [] s] t
80 | Zero : Term SIG ctx NAT
84 | Succ : Term SIG ctx NAT -> Term SIG ctx NAT
88 | Lam : {s : TY} -> Term SIG (ctx :< s) t -> Term SIG ctx (ARR s t)
92 | App : Term SIG ctx (ARR s t) -> Term SIG ctx s -> Term SIG ctx t
93 | App f t = Con APP [f, t]
99 | lift : (forall s. Elem s ctx -> Elem s ctx') ->
100 | (forall s. Elem s (ctx :< t) -> Elem s (ctx' :< t))
102 | lift f (There v) = There (f v)
105 | lifts : (bds : List kind) ->
106 | (forall s. Elem s ctx -> Elem s ctx') ->
107 | (forall s. Elem s (ctx <>< bds) -> Elem s (ctx' <>< bds))
109 | lifts (s :: ss) f = lifts ss (lift f)
112 | rename : (forall s. Elem s ctx -> Elem s ctx') ->
113 | (forall s. Term sig ctx s -> Term sig ctx' s)
116 | renames : (forall s. Elem s ctx -> Elem s ctx') ->
117 | (forall args. Args sig ctx args -> Args sig ctx' args)
119 | rename f (Var v) = Var (f v)
120 | rename f (Con c args) = Con c (renames f args)
123 | renames f (arg :: args) = rename (lifts _ f) arg :: renames f args
129 | extend : (forall s. Elem s ctx -> Term sig ctx' s) ->
130 | (forall s. Elem s (ctx :< t) -> Term sig (ctx' :< t) s)
131 | extend f Here = Var Here
132 | extend f (There v) = rename There (f v)
135 | extends : (bds : List kind) ->
136 | (forall s. Elem s ctx -> Term sig ctx' s) ->
137 | (forall s. Elem s (ctx <>< bds) -> Term sig (ctx' <>< bds) s)
139 | extends (s :: ss) f = extends ss (extend f)
142 | substitute : (forall s. Elem s ctx -> Term sig ctx' s) ->
143 | (forall s. Term sig ctx s -> Term sig ctx' s)
146 | substitutes : (forall s. Elem s ctx -> Term sig ctx' s) ->
147 | (forall args. Args sig ctx args -> Args sig ctx' args)
149 | substitute f (Var v) = f v
150 | substitute f (Con c args) = Con c (substitutes f args)
152 | substitutes f [] = []
153 | substitutes f (arg :: args) = substitute (extends _ f) arg :: substitutes f args