on master help sign in
Include reflection of the current goal in proofscript arguments
commitb65a0fbbfa13fe0fe481538823f44b9b03832328 authorJan Bessai <Jan.Bessai@tu-dortmund.de> dateMon 25 Mar 2013, 10:05 (14 years ago) parent8ce17c6
3 files changed+53−23
effects/Effects.idr+8−8 samples/reflection.idr+22−9 src/Idris/ElabTerm.hs+23−6
effects/Effects.idr+8−8
@@ -59,19 +59,19 @@ rebuildEnv xs (Drop rest) (y :: env) = y :: rebuildEnv xs rest env
5959---- The Effect EDSL itself ----
6060
6161-- some proof automation
62−findEffElem : Nat -> List (TTName, Binder TT) -> Tactic -- Nat is maximum search depth
63−findEffElem O ctxt = Refine "Here" `Seq` Solve
64−findEffElem (S n) ctxt = GoalType "EffElem"
62+findEffElem : Nat -> List (TTName, Binder TT) -> TT -> Tactic -- Nat is maximum search depth
63+findEffElem O ctxt goal = Refine "Here" `Seq` Solve
64+findEffElem (S n) ctxt goal = GoalType "EffElem"
6565 (Try (Refine "Here" `Seq` Solve)
66− (Refine "There" `Seq` (Solve `Seq` findEffElem n ctxt)))
66+ (Refine "There" `Seq` (Solve `Seq` findEffElem n ctxt goal)))
6767
68−findSubList : Nat -> List (TTName, Binder TT) -> Tactic
69−findSubList O ctxt = Refine "SubNil" `Seq` Solve
70−findSubList (S n) ctxt
68+findSubList : Nat -> List (TTName, Binder TT) -> TT -> Tactic
69+findSubList O ctxt goal = Refine "SubNil" `Seq` Solve
70+findSubList (S n) ctxt goal
7171 = GoalType "SubList"
7272 (Try (Refine "subListId" `Seq` Solve)
7373 ((Try (Refine "Keep" `Seq` Solve)
74− (Refine "Drop" `Seq` Solve)) `Seq` findSubList n ctxt))
74+ (Refine "Drop" `Seq` Solve)) `Seq` findSubList n ctxt goal))
7575
7676updateResTy : (xs : List EFFECT) -> EffElem e a xs -> e a b t ->
7777 List EFFECT
samples/reflection.idr+22−9
@@ -60,33 +60,46 @@ intEq x y = case x == y of
6060
6161-- | A tactic script to run intEq on two let-bound or introduced
6262-- arguments of the current (otherwise empty) proof context
63−firstEq : List (TTName, Binder TT) -> Tactic
64−firstEq ((_, (Let _ y))::(_, (Let _ x))::(_, Let _ f)::Nil) = Exact (App (App f x) y)
65−firstEq ((y, Lam yt)::(x, Lam xt)::(_, Let _ f)::Nil) = Exact (App (App f (P (Bound) x xt)) (P Bound y yt))
66−firstEq xs = Exact (TConst (I 0))
63+firstEq : List (TTName, Binder TT) -> TT -> Tactic
64+firstEq ((_, (Let _ y))::(_, (Let _ x))::(_, Let _ f)::Nil) _ = Exact (App (App f x) y)
65+firstEq ((y, Lam yt)::(x, Lam xt)::(_, Let _ f)::Nil) _ = Exact (App (App f (P (Bound) x xt)) (P Bound y yt))
66+firstEq xs _ = Exact (TConst (I 0))
6767
6868-- | Skip 3 arguments of the proof context and return the fourth one which
6969-- has to be introduced.
7070-- Used for the tactical dispatch example, which will push dispatch,
71−-- its current proof context and the result of dispatch applied to it
71+-- its current proof context, the goal, and the result of dispatch applied to it
7272-- first.
73−innerTac : List (TTName, Binder TT) -> Tactic
74−innerTac (_::_::_::(x, Lam xt)::_) = Exact (P Bound x xt)
73+innerTac : List (TTName, Binder TT) -> TT -> Tactic
74+innerTac (_::_::_::_::(x, Lam xt)::_) _ = Exact (P Bound x xt)
7575
7676-- | Returns the reflected representation of innerTac
7777innerTacTT : TT
7878innerTacTT = ?innerTacTTPrf
7979
8080-- | Dispatch to the reflected rep. of innerTac
81−dispatch : List (TTName, Binder TT) -> Tactic
82−dispatch xs = ApplyTactic (innerTacTT)
81+dispatch : List (TTName, Binder TT) -> TT -> Tactic
82+dispatch xs _ = ApplyTactic (innerTacTT)
8383
8484-- | Call dispatch which will then dispatch to innerTac.
8585tacticalDispatch : Int -> Int
8686tacticalDispatch = ?tacticalDispatchPrf
8787
88+-- | A tactic to get the representation of its goal
89+studyGoalTac : List (TTName, Binder TT) -> TT -> Tactic
90+studyGoalTac _ goal = Reflect goal
91+
92+-- | Returns the representation of its goal, TT
93+-- (so this is reflect on the type TT)
94+studyGoal : TT
95+studyGoal = ?studyGoalPrf
96+
8897---------- Proofs ----------
8998
99+ReflectionExamples.studyGoalPrf = proof {
100+ applyTactic studyGoalTac;
101+}
102+
90103ReflectionExamples.envTuplePrf = proof {
91104 let x = tupleType;
92105 fill x;
src/Idris/ElabTerm.hs+23−6
@@ -774,13 +774,16 @@ runTac autoSolve ist tac = do env <- get_env
774774 runT (Try l r) = do try' (runT l) (runT r) True
775775 runT (TSeq l r) = do runT l; runT r
776776 runT (ApplyTactic tm) = do tenv <- get_env -- store the environment before it is loaded with junk
777− attack -- let f : List (TTName, Binder TT) -> Tactic = tm in ...
777+ tgoal <- goal -- store the goal
778+ attack -- let f : List (TTName, Binder TT) -> TT -> Tactic = tm in ...
778779 valn <- unique_hole (MN 0 "tacval")
779780 claim valn (RBind (UN "__pi_arg")
780− (Pi (RApp listTy envTupleType)) tacticTy)
781− tacn <- unique_hole (MN 0 "tacn")
781+ (Pi (RApp listTy envTupleType))
782+ (RBind (UN "__pi_arg1") (Pi (Var $ reflm "TT")) tacticTy))
783+ tacn <- unique_hole (MN 0 "tacn" )
782784 letbind tacn (RBind (UN "__pi_arg")
783− (Pi (RApp listTy envTupleType)) tacticTy)
785+ (Pi (RApp listTy envTupleType))
786+ (RBind (UN "__pi_arg1") (Pi (Var $ reflm "TT")) tacticTy))
784787 (Var valn)
785788 focus valn
786789 elab ist toplevel False False (MN 0 "tac") tm
@@ -800,13 +803,27 @@ runTac autoSolve ist tac = do env <- get_env
800803 ctxt <- get_context
801804 env <- get_env
802805 let env'' = normalise ctxt env env'
803− -- let z : Tactic = f x
806+ -- let g : TT = reflect tgoal
807+ goalval <- unique_hole (MN 0 "letval")
808+ claim goalval (Var $ reflm "TT")
809+ letg <- unique_hole (MN 0 "letvar")
810+ letbind letg (Var $ reflm "TT") (Var goalval)
811+ focus goalval
812+ env <- get_env
813+ elab ist toplevel False False (MN 0 "tac") (PQuote (reflect tgoal))
814+ (goal', _) <- get_type_val (Var letg)
815+ ctxt <- get_context
816+ env <- get_env
817+ let goal'' = hnf ctxt env goal'
818+ -- let z : Tactic = f x g
804819 restac <- unique_hole (MN 0 "letval")
805820 claim restac tacticTy
806821 letn <- unique_hole (MN 0 "letvar")
807822 letbind letn tacticTy (Var restac)
808823 focus restac
809− elab ist toplevel False False (MN 0 "tac") (PQuote (RApp (forget tm'') (forget env'')))
824+ elab
825+ ist toplevel False False (MN 0 "tac")
826+ (PQuote (raw_apply (forget tm'') [forget env'', forget goal'']))
810827 (res, _) <- get_type_val (Var letn)
811828 ctxt <- get_context
812829 env <- get_env