on master help sign in
Improve code style in Pruviloj
8f80de4David Raymond Christiansen
libs/pruviloj/Pruviloj/Core.idr+2−2
@@ -91,7 +91,7 @@ newHole hint ty =
91|||
91|||
92||| @ tm the term that has the right type for the hole
92||| @ tm the term that has the right type for the hole
93exact : (tm : Raw) -> Elab ()
93exact : (tm : Raw) -> Elab ()
94−exact tm = do apply tm []
94+exact tm = do fill tm
95 solve
95 solve
96
96
97||| Introduce as many names as possible, returning them.
97||| Introduce as many names as possible, returning them.
@@ -178,7 +178,7 @@ data Infer : Type where
178total
178total
179inferType : (tac : Elab ()) -> Elab (TT, TT)
179inferType : (tac : Elab ()) -> Elab (TT, TT)
180inferType tac =
180inferType tac =
181− case fst !(runElab `(Infer) (startInfer *> tac)) of
181+ case fst !(runElab `(Infer) (do startInfer; tac)) of
182 `(MkInfer ~ty ~tm) => return (tm, ty)
182 `(MkInfer ~ty ~tm) => return (tm, ty)
183 _ => fail [TextPart "Not infer"]
183 _ => fail [TextPart "Not infer"]
184 where
184 where
libs/pruviloj/Pruviloj/Derive/DecEq.idr+1−3
@@ -44,9 +44,7 @@ partial -- TODO make covering/total
44matchCase : List Raw -> Elab ()
44matchCase : List Raw -> Elab ()
45matchCase [] = search
45matchCase [] = search
46matchCase (tm :: tms) =
46matchCase (tm :: tms) =
47− do hs <- induction tm
47+ do (y :: n :: _) <- induction tm
48− y <- unsafeNth 0 hs
49− n <- unsafeNth 1 hs
50
48
51 focus n; compute
49 focus n; compute
52 contra <- gensym "contra"
50 contra <- gensym "contra"
test/meta002/AgdaStyleReflection.idr+50−14
@@ -1,4 +1,4 @@
1−||| Implement an Agda-style reflection system as a DSL inside of
1+ ||| Implement an Agda-style reflection system as a DSL inside of
2||| Idris's reflected elaboration. Requires handling type class
2||| Idris's reflected elaboration. Requires handling type class
3||| resolution and implicit arguments - some of the same features as
3||| resolution and implicit arguments - some of the same features as
4||| the Idris elaborator itself.
4||| the Idris elaborator itself.
@@ -183,16 +183,49 @@ covering
183spliceTerm : Term -> Elab ()
183spliceTerm : Term -> Elab ()
184spliceTerm = spliceTerm' []
184spliceTerm = spliceTerm' []
185
185
186−||| Lift an Agda-style tactic into an Idris-style tactic
187−covering
188−quoteGoalImpl : (Term -> Term) -> Elab ()
189−quoteGoalImpl f = do compute
190− g <- goalType >>= quoteTerm
191− spliceTerm (f g)
192−
193−syntax "quoteGoal" {x} "in" [expr] = %runElab (quoteGoalImpl (\x => expr))
194
186
187+mutual
188+ instance Quotable Plicity Raw where
189+ quotedTy = `(Plicity)
190+ quote Explicit = `(Explicit)
191+ quote Implicit = `(Implicit)
192+ quote Constraint = `(Constraint)
193+
194+ instance Quotable a Raw => Quotable (Arg a) Raw where
195+ quotedTy = `(Arg ~(quotedTy {a=a}))
196+ quote (MkArg plicity argValue) = `(MkArg {a=~(quotedTy {a=a})} ~(quote plicity) ~(quote argValue) )
197+
198+ instance Quotable Term Raw where
199+ quotedTy = `(Term)
200+
201+ quote (Var k xs) = `(Var ~(quote k) ~(assert_total $ quote xs))
202+ quote (Ctor n xs) = `(Ctor ~(quote n) ~(assert_total $ quote xs))
203+ quote (TyCtor n xs) = `(TyCtor ~(quote n) ~(assert_total $ quote xs))
204+ quote (Def n xs) = `(Def ~(quote n) ~(assert_total $ quote xs))
205+ quote (Lam x) = `(Lam ~(quote x) : Term)
206+ quote (Pi x y) = `(Pi ~(quote x) ~(quote y) : Term)
207+ quote (Constant c) = `(Constant ~(quote c) : Term)
208+ quote Ty = `(Ty)
209+
210+-- ||| Lift an Agda-style tactic into an Idris-style tactic
211+-- covering
212+-- quoteGoalImpl : TTName -> Elab ()
213+-- quoteGoalImpl f = do compute
214+-- g <- goalType >>= quoteTerm
215+-- spliceTerm (f g)
216+
217+partial
218+quoteGoalImpl : Elab ()
219+quoteGoalImpl =
220+ do g <- goalType >>= quoteTerm
221+ fill (quote g)
222+ solve
223+
224+syntax "quoteGoal" {x} "in" [expr] =
225+ let z = %runElab quoteGoalImpl
226+ in (\x => expr) z
227+
195−syntax "tactic" [expr] = %runElab (quoteGoalImpl expr)
228+--syntax "tactic" [expr] = %runElab (quoteGoalImpl expr)
196
229
197
230
198
231
@@ -231,16 +264,19 @@ covering
231trivial : (goal : Term) -> Term
264trivial : (goal : Term) -> Term
232trivial = perhaps . trivial'
265trivial = perhaps . trivial'
233
266
267+gargle : Nat -> Nat -> Term
268+gargle = quoteGoal x in \a, b => x
269+
234foo : (Nat, (), Nat, Either (() -> ()) Void)
270foo : (Nat, (), Nat, Either (() -> ()) Void)
235−foo = quoteGoal x in trivial x
271+--foo = quoteGoal x in trivial x
236
272
237bar : (Nat, (), Either Void Nat, Nat -> ())
273bar : (Nat, (), Either Void Nat, Nat -> ())
238−bar = tactic trivial
274+--bar = tactic trivial
239
275
240-- When checking right hand side of baz:
276-- When checking right hand side of baz:
241-- PROOF SEARCH FAILURE is not defined.
277-- PROOF SEARCH FAILURE is not defined.
242−baz : (Nat, Void)
278+--baz : (Nat, Void)
243−baz = tactic trivial
279+--baz = tactic trivial
244
280
245-- Local Variables:
281-- Local Variables:
246-- idris-load-packages: ("pruviloj")
282-- idris-load-packages: ("pruviloj")