1module Language.Reflection
6 ||| A user-provided name
8 ||| A name in some namespace.
10 ||| The namespace is in reverse order, so `(NS (UN "foo") ["B", "A"])` represents the name `A.B.foo`
11 NS TTName (List String) |
12 ||| Machine-chosen names
14 ||| Name of something which is never used in scope
19userSuppliedName : String -> TTName
25 ||| Explicit universe level
29data NativeTy = IT8 | IT16 | IT32 | IT64
31data IntTy = ITFixed NativeTy | ITNative | ITBig | ITChar
34data ArithTy = ATInt Language.Reflection.IntTy | ATFloat
36||| Primitive constants
37data Const = I Int | BI Integer | Fl Float | Ch Char | Str String
38 | B8 Bits8 | B16 Bits16 | B32 Bits32 | B64 Bits64
39 | B8V Bits8x16 | B16V Bits16x8
40 | B32V Bits32x4 | B64V Bits64x2
41 | AType ArithTy | StrType
42 | PtrType | ManagedPtrType | BufferType | VoidType | Forgot
46abstract class ReflConst (a : Type) where
49instance ReflConst Int where
52instance ReflConst Integer where
55instance ReflConst Float where
58instance ReflConst Char where
61instance ReflConst String where
64instance ReflConst Bits8 where
67instance ReflConst Bits16 where
70instance ReflConst Bits32 where
73instance ReflConst Bits64 where
77reflectConstant: (ReflConst a) => a -> Const
78reflectConstant = toConst
81||| Types of named references
83 ||| A reference which is just bound, e.g. by intro
85 ||| A reference to a de Bruijn-indexed variable
87 ||| Data constructor with tag and number
89 ||| Type constructor with tag and number
94||| Types annotations for bound variables in different
107instance Functor Binder where
108 map f (Lam x) = Lam (f x)
109 map f (Pi x k) = Pi (f x) (f k)
110 map f (Let x y) = Let (f x) (f y)
111 map f (NLet x y) = NLet (f x) (f y)
112 map f (Hole x) = Hole (f x)
113 map f (GHole x) = GHole (f x)
114 map f (Guess x y) = Guess (f x) (f y)
115 map f (PVar x) = PVar (f x)
116 map f (PVTy x) = PVTy (f x)
118instance Foldable Binder where
119 foldr f z (Lam x) = f x z
120 foldr f z (Pi x k) = f x (f k z)
121 foldr f z (Let x y) = f x (f y z)
122 foldr f z (NLet x y) = f x (f y z)
123 foldr f z (Hole x) = f x z
124 foldr f z (GHole x) = f x z
125 foldr f z (Guess x y) = f x (f y z)
126 foldr f z (PVar x) = f x z
127 foldr f z (PVTy x) = f x z
129instance Traversable Binder where
130 traverse f (Lam x) = [| Lam (f x) |]
131 traverse f (Pi x k) = [| Pi (f x) (f k) |]
132 traverse f (Let x y) = [| Let (f x) (f y) |]
133 traverse f (NLet x y) = [| NLet (f x) (f y) |]
134 traverse f (Hole x) = [| Hole (f x) |]
135 traverse f (GHole x) = [| GHole (f x) |]
136 traverse f (Guess x y) = [| Guess (f x) (f y) |]
137 traverse f (PVar x) = [| PVar (f x) |]
138 traverse f (PVTy x) = [| PVTy (f x) |]
141||| Reflection of the well typed core language
143 ||| A reference to some name (P for Parameter)
144 P NameType TTName TT |
145 ||| de Bruijn variables
148 Bind TTName (Binder TT) TT |
149 ||| Apply one term to another
153 ||| Argument projection; runtime only
159 ||| The type of types along (with universe constraints)
163||| Raw terms without types
165 ||| Variables, global or local
168 RBind TTName (Binder Raw) Raw |
171 ||| The type of types
178||| Error reports are a list of report parts
179data ErrorReportPart =
180 ||| A human-readable string
182 ||| An Idris name (to be semantically coloured)
184 ||| An Idris term, to be pretty printed
186 ||| An indented sub-report, to provide more details
187 SubReport (List ErrorReportPart)
188%name ErrorReportPart part, p
190||| A representation of Idris's tactics that can be returned from custom
191||| tactic implementations. Generate these using `applyTactic`.
193 ||| Try the first tactic and resort to the second one on failure
195 ||| Only run if the goal has the right type
196 GoalType String Tactic |
197 ||| Resolve function name, find matching arguments in the
198 ||| context and compute the proof target
200 ||| Apply both tactics in sequence
202 ||| Intelligently construct the proof target from the context
204 ||| Build a proof by applying contructors up to a maximum depth
206 ||| Resolve a type class
208 ||| Infer the proof target from the context
210 ||| introduce all variables into the context
212 ||| Introduce a named variable into the context, use the
213 ||| first one if the given name is not found
215 ||| Invoke the reflected rep. of another tactic
217 ||| Turn a value into its reflected representation
219 ||| Use a `%reflection` function
221 ||| Turn a raw value back into a term
223 ||| Use the given value to conclude the proof
225 ||| Focus on a particular hole
227 ||| Rewrite with an equality
229 ||| Perform induction on a particular expression
231 ||| Perform case analysis on a particular expression
233 ||| Name a reflected term
235 ||| Name a reflected term and type it
236 LetTacTy TTName TT TT |
237 ||| Normalise the goal
241 ||| Fail with an error message
242 Fail (List ErrorReportPart)
243%name Tactic tac, tac'
246||| Things with a canonical representation in the TT datatype.
248||| This type class is intended to be used during proof automation and the
249||| construction of custom tactics.
251||| @ a the type to be quoted
252class Quotable a where
253 ||| A representation of the type `a`.
255 ||| This is to enable quoting polymorphic datatypes
258 ||| Quote a particular element of `a`.
260 ||| Each equation should look something like ```quote (Foo x y) = `(Foo ~(quote x) ~(quote y))```
263instance Quotable Nat where
267 quote (S k) = `(S ~(quote k))
269instance Quotable Int where
271 quote x = TConst (I x)
273instance Quotable Float where
275 quote x = TConst (Fl x)
277instance Quotable Char where
279 quote x = TConst (Ch x)
281instance Quotable Bits8 where
283 quote x = TConst (B8 x)
285instance Quotable Bits16 where
287 quote x = TConst (B16 x)
289instance Quotable Bits32 where
291 quote x = TConst (B32 x)
293instance Quotable Bits64 where
295 quote x = TConst (B64 x)
297instance Quotable Integer where
298 quotedTy = `(Integer)
299 quote x = TConst (BI x)
301instance Quotable Bits8x16 where
302 quotedTy = `(Bits8x16)
303 quote x = TConst (B8V x)
305instance Quotable Bits16x8 where
306 quotedTy = `(Bits16x8)
307 quote x = TConst (B16V x)
309instance Quotable Bits32x4 where
310 quotedTy = `(Bits32x4)
311 quote x = TConst (B32V x)
313instance Quotable Bits64x2 where
314 quotedTy = `(Bits64x2)
315 quote x = TConst (B64V x)
317instance Quotable String where
319 quote x = TConst (Str x)
321instance Quotable NameType where
322 quotedTy = `(NameType)
323 quote Bound = `(Bound)
325 quote (DCon x y) = `(DCon ~(quote x) ~(quote y))
326 quote (TCon x y) = `(TCon ~(quote x) ~(quote y))
328instance Quotable a => Quotable (List a) where
329 quotedTy = `(List ~(quotedTy {a=a}))
330 quote [] = `(List.Nil {a=~quotedTy})
331 quote (x :: xs) = `(List.(::) {a=~quotedTy} ~(quote x) ~(quote xs))
333instance Quotable TTName where
335 quote (UN x) = `(UN ~(quote x))
336 quote (NS n xs) = `(NS ~(quote n) ~(quote xs))
337 quote (MN x y) = `(MN ~(quote x) ~(quote y))
338 quote NErased = `(NErased)
340instance Quotable NativeTy where
341 quotedTy = `(NativeTy)
342 quote IT8 = `(Reflection.IT8)
343 quote IT16 = `(Reflection.IT16)
344 quote IT32 = `(Reflection.IT32)
345 quote IT64 = `(Reflection.IT64)
347instance Quotable Reflection.IntTy where
348 quotedTy = `(Reflection.IntTy)
349 quote (ITFixed x) = `(ITFixed ~(quote x))
350 quote ITNative = `(Reflection.ITNative)
351 quote ITBig = `(ITBig)
352 quote ITChar = `(Reflection.ITChar)
353 quote (ITVec x y) = `(ITVec ~(quote x) ~(quote y))
355instance Quotable ArithTy where
356 quotedTy = `(ArithTy)
357 quote (ATInt x) = `(ATInt ~(quote x))
358 quote ATFloat = `(ATFloat)
360instance Quotable Const where
362 quote (I x) = `(I ~(quote x))
363 quote (BI x) = `(BI ~(quote x))
364 quote (Fl x) = `(Fl ~(quote x))
365 quote (Ch x) = `(Ch ~(quote x))
366 quote (Str x) = `(Str ~(quote x))
367 quote (B8 x) = `(B8 ~(quote x))
368 quote (B16 x) = `(B16 ~(quote x))
369 quote (B32 x) = `(B32 ~(quote x))
370 quote (B64 x) = `(B64 ~(quote x))
371 quote (B8V xs) = `(B8V ~(quote xs))
372 quote (B16V xs) = `(B16V ~(quote xs))
373 quote (B32V xs) = `(B32V ~(quote xs))
374 quote (B64V xs) = `(B64V ~(quote xs))
375 quote (AType x) = `(AType ~(quote x))
376 quote StrType = `(StrType)
377 quote PtrType = `(PtrType)
378 quote ManagedPtrType = `(ManagedPtrType)
379 quote BufferType = `(BufferType)
380 quote VoidType = `(VoidType)
381 quote Forgot = `(Forgot)
384instance Quotable TTUExp where
386 quote (UVar x) = `(UVar ~(quote x))
387 quote (UVal x) = `(UVal ~(quote x))
390 instance Quotable TT where
392 quote (P nt n tm) = `(P ~(quote nt) ~(quote n) ~(quote tm))
393 quote (V x) = `(V ~(quote x))
394 quote (Bind n b tm) = `(Bind ~(quote n) ~(assert_total (quote b)) ~(quote tm))
395 quote (App f x) = `(App ~(quote f) ~(quote x))
396 quote (TConst c) = `(TConst ~(quote c))
397 quote (Proj tm x) = `(Proj ~(quote tm) ~(quote x))
398 quote Erased = `(Erased)
399 quote Impossible = `(Impossible)
400 quote (TType uexp) = `(TType ~(quote uexp))
402 instance Quotable (Binder TT) where
403 quotedTy = `(Binder TT)
404 quote (Lam x) = `(Lam {a=TT} ~(assert_total (quote x)))
405 quote (Pi x k) = `(Pi {a=TT} ~(assert_total (quote x))
406 ~(assert_total (quote k)))
407 quote (Let x y) = `(Let {a=TT} ~(assert_total (quote x))
408 ~(assert_total (quote y)))
409 quote (NLet x y) = `(NLet {a=TT} ~(assert_total (quote x))
410 ~(assert_total (quote y)))
411 quote (Hole x) = `(Hole {a=TT} ~(assert_total (quote x)))
412 quote (GHole x) = `(GHole {a=TT} ~(assert_total (quote x)))
413 quote (Guess x y) = `(Guess {a=TT} ~(assert_total (quote x))
414 ~(assert_total (quote y)))
415 quote (PVar x) = `(PVar {a=TT} ~(assert_total (quote x)))
416 quote (PVTy x) = `(PVTy {a=TT} ~(assert_total (quote x)))
419instance Quotable ErrorReportPart where
420 quotedTy = `(ErrorReportPart)
421 quote (TextPart x) = `(TextPart ~(quote x))
422 quote (NamePart n) = `(NamePart ~(quote n))
423 quote (TermPart tm) = `(TermPart ~(quote tm))
424 quote (SubReport xs) = `(SubReport ~(assert_total $ quote xs))
428 quoteRaw (Var n) = `(Var ~(quote n))
429 quoteRaw (RBind n b tm) = `(RBind ~(quote n) ~(assert_total $ quoteRawBinder b) ~(quoteRaw tm))
430 quoteRaw (RApp tm tm') = `(RApp ~(quoteRaw tm) ~(quoteRaw tm'))
431 quoteRaw RType = `(RType)
432 quoteRaw (RForce tm) = `(RForce ~(quoteRaw tm))
433 quoteRaw (RConstant c) = `(RConstant ~(quote c))
435 quoteRawBinder : Binder Raw -> TT
436 quoteRawBinder (Lam x) = `(Lam {a=Raw} ~(quoteRaw x))
437 quoteRawBinder (Pi x k) = `(Pi {a=Raw} ~(quoteRaw x) ~(quoteRaw k))
438 quoteRawBinder (Let x y) = `(Let {a=Raw} ~(quoteRaw x) ~(quoteRaw y))
439 quoteRawBinder (NLet x y) = `(NLet {a=Raw} ~(quoteRaw x) ~(quoteRaw y))
440 quoteRawBinder (Hole x) = `(Hole {a=Raw} ~(quoteRaw x))
441 quoteRawBinder (GHole x) = `(GHole {a=Raw} ~(quoteRaw x))
442 quoteRawBinder (Guess x y) = `(Guess {a=Raw} ~(quoteRaw x) ~(quoteRaw y))
443 quoteRawBinder (PVar x) = `(PVar {a=Raw} ~(quoteRaw x))
444 quoteRawBinder (PVTy x) = `(PVTy {a=Raw} ~(quoteRaw x))
446instance Quotable Raw where
450instance Quotable (Binder Raw) where
451 quotedTy = `(Binder Raw)
452 quote = quoteRawBinder
454instance Quotable Tactic where
456 quote (Try tac tac') = `(Try ~(quote tac) ~(quote tac'))
457 quote (GoalType x tac) = `(GoalType ~(quote x) ~(quote tac))
458 quote (Refine n) = `(Refine ~(quote n))
459 quote (Seq tac tac') = `(Seq ~(quote tac) ~(quote tac'))
460 quote Trivial = `(Trivial)
461 quote (Search x) = `(Search ~(quote x))
462 quote Instance = `(Instance)
463 quote Solve = `(Solve)
464 quote Intros = `(Intros)
465 quote (Intro n) = `(Intro ~(quote n))
466 quote (ApplyTactic tm) = `(ApplyTactic ~(quote tm))
467 quote (Reflect tm) = `(Reflect ~(quote tm))
468 quote (ByReflection tm) = `(ByReflection ~(quote tm))
469 quote (Fill tm) = `(Fill ~(quote tm))
470 quote (Exact tm) = `(Exact ~(quote tm))
471 quote (Focus n) = `(Focus ~(quote n))
472 quote (Rewrite tm) = `(Rewrite ~(quote tm))
473 quote (Induction tm) = `(Induction ~(quote tm))
474 quote (Case tm) = `(Case ~(quote tm))
475 quote (LetTac n tm) = `(LetTac ~(quote n) ~(quote tm))
476 quote (LetTacTy n tm tm') = `(LetTacTy ~(quote n) ~(quote tm) ~(quote tm'))
477 quote Compute = `(Compute)
479 quote (Fail xs) = `(Fail ~(quote xs))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list