-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypedTerm.hs
82 lines (73 loc) · 2.64 KB
/
TypedTerm.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module TypedTerm where
import Term
data CheckedTerm =
Synthed SynthedTerm
| TLam CheckedTerm
| TAddProof CheckedTerm CheckedTerm CheckedTerm
| TPair CheckedTerm CheckedTerm
| TLetC SynthedTerm CheckedTerm
deriving Show
data SynthedTerm =
CheckedTerm ::: CheckedTerm
| TAbort CheckedTerm
| TZero
| TSucc CheckedTerm
| TNatRec CheckedTerm CheckedTerm CheckedTerm CheckedTerm
| TUseProof CheckedTerm CheckedTerm CheckedTerm CheckedTerm CheckedTerm
| TProj1 SynthedTerm
| TProj2 SynthedTerm
| TGetProof CheckedTerm SynthedTerm
| TUseSquash SynthedTerm CheckedTerm CheckedTerm
| TPi SynthedTerm SynthedTerm
| TBottom
| TTop
| TNat
| TRefine SynthedTerm SynthedTerm
| TSigma SynthedTerm SynthedTerm
| TSquash SynthedTerm
| TSort Level
| TVar Int
| TApp SynthedTerm CheckedTerm
| TLetS SynthedTerm SynthedTerm
deriving Show
tSortN :: Int -> SynthedTerm
tSortN = TSort . LevelN
tSortW :: SynthedTerm
tSortW = TSort LevelW
tStar :: SynthedTerm
tStar = tSortN 0
tBox :: SynthedTerm
tBox = tSortN 1
eraseChecked :: CheckedTerm -> Term
eraseChecked (Synthed x) = eraseSynthed x
eraseChecked (TLam x) = Lam (eraseChecked x)
eraseChecked (TAddProof x t p) =
AddProof (eraseChecked x) (eraseChecked t) (Irrel $ eraseChecked p)
eraseChecked (TPair a b) =
Pair (eraseChecked a) (eraseChecked b)
eraseChecked (TLetC x y) = Substed (bindingSubst (eraseSynthed x)) (eraseChecked y)
eraseSynthed :: SynthedTerm -> Term
eraseSynthed (x ::: _) = eraseChecked x
eraseSynthed (TAbort x) = Abort $ Irrel $ eraseChecked x
eraseSynthed (TZero) = Zero
eraseSynthed (TSucc x) = Succ $ eraseChecked x
eraseSynthed (TNatRec t x y n) =
NatRec (eraseChecked t) (eraseChecked x) (eraseChecked y) (eraseChecked n)
eraseSynthed (TUseProof tx tp x ty y) =
UseProof (eraseChecked tx) (eraseChecked tp) (eraseChecked x)
(eraseChecked ty) (eraseChecked y)
eraseSynthed (TProj1 p) = Proj1 $ eraseSynthed p
eraseSynthed (TProj2 p) = Proj2 $ eraseSynthed p
eraseSynthed (TGetProof tp x) = GetProof (eraseChecked tp) (eraseSynthed x)
eraseSynthed (TUseSquash p ty y) = UseSquash (eraseSynthed p) (eraseChecked ty) (eraseChecked y)
eraseSynthed (TPi x y) = Pi (eraseSynthed x) (eraseSynthed y)
eraseSynthed (TBottom) = Bottom
eraseSynthed (TTop) = Top
eraseSynthed (TNat) = Nat
eraseSynthed (TRefine x p) = Refine (eraseSynthed x) (eraseSynthed p)
eraseSynthed (TSigma x y) = Sigma (eraseSynthed x) (eraseSynthed y)
eraseSynthed (TSquash x) = Squash $ eraseSynthed x
eraseSynthed (TSort k) = Sort k
eraseSynthed (TVar n) = Var n
eraseSynthed (TApp x y) = App (eraseSynthed x) (eraseChecked y)
eraseSynthed (TLetS x y) = Substed (bindingSubst (eraseSynthed x)) (eraseSynthed y)