on aa42f71 help sign in
185 lines 6.7 kB history raw
1module Language.Reflection.Utils
3--------------------------------------------------------
4-- Tactic construction conveniences
5--------------------------------------------------------
7seq : List Tactic -> Tactic
8seq [] = GoalType "This is an impossible case" Trivial
9seq [t] = t
10seq (t::ts) = t `Seq` seq ts
12try : List Tactic -> Tactic
13try [] = GoalType "This is an impossible case" Trivial
14try [t] = t
15try (t::ts) = t `Try` seq ts
18--------------------------------------------------------
19-- For use in tactic scripts
20--------------------------------------------------------
21mkPair : a -> b -> (a, b)
22mkPair a b = (a, b)
25--------------------------------------------------------
26-- Tools for constructing proof terms directly
27--------------------------------------------------------
29getUName : TTName -> Maybe String
30getUName (UN n) = Just n
31getUName (NS n ns) = getUName n
32getUName _ = Nothing
34unApply : TT -> (TT, List TT)
35unApply t = unA t []
36 where unA : TT -> List TT -> (TT, List TT)
37 unA (App fn arg) args = unA fn (arg::args)
38 unA tm args = (tm, args)
40mkApp : TT -> List TT -> TT
41mkApp tm [] = tm
42mkApp tm (a::as) = mkApp (App tm a) as
44binderTy : (Eq t) => Binder t -> t
45binderTy (Lam t) = t
46binderTy (Pi t) = t
47binderTy (Let t1 t2) = t1
48binderTy (NLet t1 t2) = t1
49binderTy (Hole t) = t
50binderTy (GHole t) = t
51binderTy (Guess t1 t2) = t1
52binderTy (PVar t) = t
53binderTy (PVTy t) = t
55instance Show TTName where
56 show (UN str) = "(UN " ++ str ++ ")"
57 show (NS n ns) = "(NS " ++ show n ++ " " ++ show ns ++ ")"
58 show (MN i str) = "(MN " ++ show i ++ " " ++ show str ++ ")"
59 show NErased = "NErased"
61instance Eq TTName where
62 (UN str1) == (UN str2) = str1 == str2
63 (NS n ns) == (NS n' ns') = n == n' && ns == ns'
64 (MN i str) == (MN i' str') = i == i' && str == str'
65 NErased == NErased = True
66 x == y = False
68instance Show TTUExp where
69 show (UVar i) = "(UVar " ++ show i ++ ")"
70 show (UVal i) = "(UVal " ++ show i ++ ")"
72instance Eq TTUExp where
73 (UVar i) == (UVar j) = i == j
74 (UVal i) == (UVal j) = i == j
75 x == y = False
77instance Show Const where
78 show (I i) = "(I " ++ show i ++ ")"
79 show (BI n) = "(BI " ++ show n ++ ")"
80 show (Fl f) = "(Fl " ++ show f ++ ")"
81 show (Ch c) = "(Ch " ++ show c ++ ")"
82 show (Str str) = "(Str " ++ show str ++ ")"
83 show IType = "IType"
84 show BIType = "BIType"
85 show FlType = "FlType"
86 show ChType = "ChType"
87 show StrType = "StrType"
88 show (B8 b) = "(B8 ...)"
89 show (B16 b) = "(B16 ...)"
90 show (B32 b) = "(B32 ...)"
91 show (B64 b) = "(B64 ...)"
92 show B8Type = "B8Type"
93 show B16Type = "B16Type"
94 show B32Type = "B32Type"
95 show B64Type = "B64Type"
96 show PtrType = "PtrType"
97 show VoidType = "VoidType"
98 show Forgot = "Forgot"
100instance Eq Const where
101 (I i) == (I i') = i == i'
102 (BI n) == (BI n') = n == n'
103 (Fl f) == (Fl f') = f == f'
104 (Ch c) == (Ch c') = c == c'
105 (Str str) == (Str str') = str == str'
106 IType == IType = True
107 BIType == BIType = True
108 FlType == FlType = True
109 ChType == ChType = True
110 StrType == StrType = True
111 (B8 b) == (B8 b') = False -- FIXME: b == b'
112 (B16 b) == (B16 b') = False -- FIXME: b == b'
113 (B32 b) == (B32 b') = False -- FIXME: b == b'
114 (B64 b) == (B64 b') = False -- FIXME: b == b'
115 B8Type == B8Type = True
116 B16Type == B16Type = True
117 B32Type == B32Type = True
118 B64Type == B64Type = True
119 PtrType == PtrType = True
120 VoidType == VoidType = True
121 Forgot == Forgot = True
122 x == y = False
124instance Show NameType where
125 show Bound = "Bound"
126 show Ref = "Ref"
127 show (DCon t ar) = "(DCon " ++ show t ++ " " ++ show ar ++ ")"
128 show (TCon t ar) = "(TCon " ++ show t ++ " " ++ show ar ++ ")"
130instance Eq NameType where
131 Bound == Bound = True
132 Ref == Ref = True
133 (DCon t ar) == (DCon t' ar') = t == t' && ar == ar'
134 (TCon t ar) == (TCon t' ar') = t == t' && ar == ar'
135 x == y = False
137instance (Show a) => Show (Binder a) where
138 show (Lam t) = "(Lam " ++ show t ++ ")"
139 show (Pi t) = "(Pi " ++ show t ++ ")"
140 show (Let t1 t2) = "(Let " ++ show t1 ++ " " ++ show t2 ++ ")"
141 show (NLet t1 t2) = "(NLet " ++ show t1 ++ " " ++ show t2 ++ ")"
142 show (Hole t) = "(Hole " ++ show t ++ ")"
143 show (GHole t) = "(GHole " ++ show t ++ ")"
144 show (Guess t1 t2) = "(Guess " ++ show t1 ++ " " ++ show t2 ++ ")"
145 show (PVar t) = "(PVar " ++ show t ++ ")"
146 show (PVTy t) = "(PVTy " ++ show t ++ ")"
148instance (Eq a) => Eq (Binder a) where
149 (Lam t) == (Lam t') = t == t'
150 (Pi t) == (Pi t') = t == t'
151 (Let t1 t2) == (Let t1' t2') = t1 == t1' && t2 == t2'
152 (NLet t1 t2) == (NLet t1' t2') = t1 == t1' && t2 == t2'
153 (Hole t) == (Hole t') = t == t'
154 (GHole t) == (GHole t') = t == t'
155 (Guess t1 t2) == (Guess t1' t2') = t1 == t1' && t2 == t2'
156 (PVar t) == (PVar t') = t == t'
157 (PVTy t) == (PVTy t') = t == t'
158 x == y = False
160instance Show TT where
161 show = my_show
162 where %assert_total my_show : TT -> String
163 my_show (P nt n t) = "(P " ++ show nt ++ " " ++ show n ++ " " ++ show t ++ ")"
164 my_show (V i) = "(V " ++ show i ++ ")"
165 my_show (Bind n b t) = "(Bind " ++ show n ++ " " ++ show b ++ " " ++ show t ++ ")"
166 my_show (App t1 t2) = "(App " ++ show t1 ++ " " ++ show t2 ++ ")"
167 my_show (TConst c) = "(TConst " ++ show c ++ ")"
168 my_show (Proj tm i) = "(Proj " ++ show tm ++ " " ++ show i ++ ")"
169 my_show Erased = "Erased"
170 my_show Impossible = "Impossible"
171 my_show (TType u) = "(TType " ++ show u ++ ")"
173instance Eq TT where
174 a == b = equalp a b
175 where %assert_total equalp : TT -> TT -> Bool
176 equalp (P nt n t) (P nt' n' t') = nt == nt' && n == n' && t == t'
177 equalp (V i) (V i') = i == i'
178 equalp (Bind n b t) (Bind n' b' t') = n == n' && b == b' && t == t'
179 equalp (App t1 t2) (App t1' t2') = t1 == t1' && t2 == t2'
180 equalp (TConst c) (TConst c') = c == c'
181 equalp (Proj tm i) (Proj tm' i') = tm == tm' && i == i'
182 equalp Erased Erased = True
183 equalp Impossible Impossible = True
184 equalp (TType u) (TType u') = u == u'
185 equalp x y = False