Skip to content

Commit f7ea9e5

Browse files
committed
Split out the attemptWhen combinator
1 parent 5094a0c commit f7ea9e5

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

plugins/hls-tactics-plugin/src/Wingman/Machinery.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ unify goal inst = do
223223
Nothing -> throwError (UnificationError inst goal)
224224

225225

226+
------------------------------------------------------------------------------
227+
-- | Prefer the first tactic to the second, if the bool is true. Otherwise, just run the second tactic.
228+
--
229+
-- This is useful when you have a clever pruning solution that isn't always
230+
-- applicable.
231+
attemptWhen :: TacticsM a -> TacticsM a -> Bool -> TacticsM a
232+
attemptWhen _ t2 False = t2
233+
attemptWhen t1 t2 True = commit t1 t2
234+
235+
226236
------------------------------------------------------------------------------
227237
-- | Get the class methods of a 'PredType', correctly dealing with
228238
-- instantiation of quantified class types.

plugins/hls-tactics-plugin/src/Wingman/Tactics.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,13 @@ destructOrHomoAuto hi = tracing "destructOrHomoAuto" $ do
131131
let g = unCType $ jGoal jdg
132132
ty = unCType $ hi_type hi
133133

134-
let do_destruct = rule $ destruct' (const subgoal) hi
135-
136-
case (splitTyConApp_maybe g, splitTyConApp_maybe ty) of
137-
(Just (gtc, apps), Just (tytc, _)) | gtc == tytc ->
138-
commit
139-
(rule $ destruct' (\dc jdg -> buildDataCon False jdg dc apps) hi)
140-
do_destruct
141-
_ -> do_destruct
134+
attemptWhen
135+
(rule $ destruct' (\dc jdg ->
136+
buildDataCon False jdg dc $ snd $ splitAppTys g) hi)
137+
(rule $ destruct' (const subgoal) hi)
138+
$ case (splitTyConApp_maybe g, splitTyConApp_maybe ty) of
139+
(Just (gtc, _), Just (tytc, _)) -> gtc == tytc
140+
_ -> False
142141

143142

144143
------------------------------------------------------------------------------

0 commit comments

Comments
 (0)