on master help sign in
Changes after review: refactor, docs, tests
42b2f8dJoomy Korkut
libs/pruviloj/Pruviloj/Core.idr+12−11
@@ -257,22 +257,23 @@ unproduct tm =
257 try (unproduct (Var n2))
257 try (unproduct (Var n2))
258
258
259||| Try to apply the constructors of the goal data type one by one,
259||| 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.
261||| Similar to `constructor` in Coq.
264||| Similar to `constructor` in Coq.
262construct : Elab (List TTName)
265construct : Elab (List TTName)
263−construct =
264− do g <- goalType
265− case headName g of
266+construct = case headName !goalType of
266− Nothing =>
267+ Nothing =>
267− fail [RawPart g, TextPart "is not a type declared with the data keyword"]
268+ fail [TextPart "Goal is not of a type declared with the data keyword"]
268− Just h =>
269+ Just h =>
269− choiceMap (\(n, xs, _) => apply (Var n) (map shouldUnify xs) <* solve)
270+ choiceMap (\(n, xs, _) => apply (Var n) (map shouldUnify xs) <* solve)
270− !(constructors <$> lookupDatatypeExact h)
271+ !(constructors <$> lookupDatatypeExact h)
272+ <|> fail [TextPart "No constructors apply"]
271 where
273 where
272 shouldUnify : CtorArg -> Bool
274 shouldUnify : CtorArg -> Bool
273− shouldUnify (CtorParameter _) = True
274 shouldUnify (CtorField (MkFunArg _ _ Explicit _)) = False
275 shouldUnify (CtorField (MkFunArg _ _ Explicit _)) = False
275− shouldUnify (CtorField (MkFunArg _ _ _ _)) = True
276+ shouldUnify _ = True
276
277
277||| A special-purpose tactic that attempts to solve a goal using
278||| A special-purpose tactic that attempts to solve a goal using
278||| `Refl`. This is useful for ensuring that goals in fact are trivial
279||| `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) ->
66 l ++ [] = l
66 l ++ [] = l
67appendNilRightId = %runElab mush
67appendNilRightId = %runElab mush
68
68
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+
69-- Local Variables:
82-- Local Variables:
70-- idris-load-packages: ("pruviloj")
83-- idris-load-packages: ("pruviloj")
71-- End:
84-- End: