on master help sign in
Merge pull request #4099 from joom/master
a3583beDavid Christiansen
CHANGELOG.md+1−1
@@ -13,7 +13,7 @@
13
13
14+ Added `Text.Literate`, a module for working with literate source files.
14+ Added `Text.Literate`, a module for working with literate source files.
15+ Added `Data.IORef`, for working with mutable references in `IO`.
15+ Added `Data.IORef`, for working with mutable references in `IO`.
16−+ Added `discriminate` and `splitPair` tactics to Pruviloj.
16++ Added `discriminate` and `construct` tactics to Pruviloj.
17
17
18## Tool Updates
18## Tool Updates
19+ Private functions are no longer visible in the REPL except for modules
19+ Private functions are no longer visible in the REPL except for modules
libs/pruviloj/Pruviloj/Core.idr+18−14
@@ -256,20 +256,24 @@ unproduct tm =
256 try (unproduct (Var n1))
256 try (unproduct (Var n1))
257 try (unproduct (Var n2))
257 try (unproduct (Var n2))
258
258
259−||| If the goal is a tuple or a dependent pair, then split it into
259+||| Try to apply the constructors of the goal data type one by one,
260−||| two goals and return the new goal names.
260+||| and apply the first one that works. If one of the constructors work,
261−||| It fails if the goal is neither a `Pair` nor a `DPair`.
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.
264+||| Similar to `constructor` in Coq.
262−splitPair : Elab (TTName, TTName)
265+construct : Elab (List TTName)
263−splitPair =
264− let bug = [TextPart "Splitting created wrong number of holes"] in
265− case !goalType of
266+construct = case headName !goalType of
266− `(Pair ~A ~B) => do [x, y] <- apply `(MkPair {A=~A} {B=~B}) [False, False]
267+ Nothing =>
267− | _ => fail bug
268− solve ; pure (x, y)
269− `(DPair ~A ~Pr) => do [x, y] <- apply `(MkDPair {a=~A} {P=~Pr}) [False, False]
270− | _ => fail bug
271− solve ; pure (x, y)
272− _ => fail [TextPart "Goal is not a pair"]
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"]
273+ where
274+ shouldUnify : CtorArg -> Bool
275+ shouldUnify (CtorField (MkFunArg _ _ Explicit _)) = False
276+ shouldUnify _ = True
273
277
274||| A special-purpose tactic that attempts to solve a goal using
278||| A special-purpose tactic that attempts to solve a goal using
275||| `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/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: