on master help sign in
Changes after review: refactor, docs, tests
commit42b2f8d948b914b2799842abdb1743614f346f3a authorJoomy Korkut <joomy@cattheory.com> dateWed 4 Oct 2017, 00:51 (9 years ago) parent773f417
3 files changed+31−11
libs/pruviloj/Pruviloj/Core.idr+12−11 test/pruviloj001/expected+6 test/pruviloj001/pruviloj001.idr+13
libs/pruviloj/Pruviloj/Core.idr+12−11
@@ -257,22 +257,23 @@ unproduct tm =
257257 try (unproduct (Var n2))
258258
259259||| Try to apply the constructors of the goal data type one by one,
260−||| and apply the first one that works.
260+||| and apply the first one that works. If one of the constructors work,
261+||| the explicit arguments to the constructor are created as new holes and
262+||| the hole names are returned in a list. The parameters of the type and
263+||| the implicit arguments of the constructor will be solved by unification.
261264||| Similar to `constructor` in Coq.
262265construct : Elab (List TTName)
263−construct =
264− do g <- goalType
265− case headName g of
266− Nothing =>
267− fail [RawPart g, TextPart "is not a type declared with the data keyword"]
268− Just h =>
269− choiceMap (\(n, xs, _) => apply (Var n) (map shouldUnify xs) <* solve)
270− !(constructors <$> lookupDatatypeExact h)
266+construct = case headName !goalType of
267+ Nothing =>
268+ fail [TextPart "Goal is not of a type declared with the data keyword"]
269+ Just h =>
270+ choiceMap (\(n, xs, _) => apply (Var n) (map shouldUnify xs) <* solve)
271+ !(constructors <$> lookupDatatypeExact h)
272+ <|> fail [TextPart "No constructors apply"]
271273 where
272274 shouldUnify : CtorArg -> Bool
273− shouldUnify (CtorParameter _) = True
274275 shouldUnify (CtorField (MkFunArg _ _ Explicit _)) = False
275− shouldUnify (CtorField (MkFunArg _ _ _ _)) = True
276+ shouldUnify _ = True
276277
277278||| A special-purpose tactic that attempts to solve a goal using
278279||| `Refl`. This is useful for ensuring that goals in fact are trivial
test/pruviloj001/expected+6
@@ -0,0 +1,6 @@
1+pruviloj001.idr:74:9:
2+Main.evenZ has a name which may be implicitly bound.
3+This is likely to lead to problems!
4+pruviloj001.idr:75:10:
5+Main.evenSS has a name which may be implicitly bound.
6+This is likely to lead to problems!
test/pruviloj001/pruviloj001.idr+13
@@ -66,6 +66,19 @@ appendNilRightId : (l : List a) ->
6666 l ++ [] = l
6767appendNilRightId = %runElab mush
6868
69+pair : a -> b -> (a, b)
70+pair = %runElab (do intros ; construct ; hypothesis ; hypothesis)
71+
72+data Even : Nat -> Type where
73+ evenZ : Even Z
74+ evenSS : Even n -> Even (S (S n))
75+
76+even6 : Even 6
77+even6 = %runElab (do construct ; construct ; construct ; construct ; skip)
78+
79+even6' : Even 6
80+even6' = %runElab (repeatUntilFail (ignore construct))
81+
6982-- Local Variables:
7083-- idris-load-packages: ("pruviloj")
7184-- End: