@@ -140,9 +140,13 @@ elab ist info pattern tcgen fn tm
140 pimp (MN 0 "P") Placeholder,
140 pimp (MN 0 "P") Placeholder,
141 pexp l, pexp r])
141 pexp l, pexp r])
142 elab' ina (PAlternative True as)
142 elab' ina (PAlternative True as)
145+ let (tc, _) = unApply ty
146+ let as' = pruneByType tc ctxt as
143− = let as' = pruneAlt as in
147+ let as'' = as' -- pruneAlt as'
144− try (tryAll (zip (map (elab' ina) as') (map showHd as')))
148+ try (tryAll (zip (map (elab' ina) as'') (map showHd as'')))
145− (tryAll (zip (map (elab' ina) as) (map showHd as)))
149+ (tryAll (zip (map (elab' ina) as') (map showHd as')))
146 where showHd (PApp _ h _) = show h
150 where showHd (PApp _ h _) = show h
147 showHd x = show x
151 showHd x = show x
148 elab' ina (PAlternative False as)
152 elab' ina (PAlternative False as)
@@ -356,6 +360,29 @@ pruneAlt xs = map prune xs
356 headIs f (PApp _ f' _) = headIs f f'
360 headIs f (PApp _ f' _) = headIs f f'
357 headIs f _ = True -- keep if it's not an application
361 headIs f _ = True -- keep if it's not an application
363+-- Rule out alternatives that don't return the same type as the head of the goal
364+-- (If there are none left as a result, do nothing)
366+pruneByType :: Term -> Context -> [PTerm] -> [PTerm]
367+pruneByType (P _ n _) c as
368+ = let as' = filter (headIs n) as in
373+ headIs f (PApp _ (PRef _ f') _) = typeHead f f'
374+ headIs f (PApp _ f' _) = headIs f f'
375+ headIs f (PPi _ _ _ sc) = headIs f sc
376+ headIs _ _ = True -- keep if it's not an application
378+ typeHead f f' = case lookupTy Nothing f' c of
379+ [ty] -> case unApply (getRetTy ty) of
380+ (P _ ftyn _, _) -> ftyn == f
384+pruneByType t _ as = as
359trivial :: IState -> ElabD ()
386trivial :: IState -> ElabD ()
360trivial ist = try (do elab ist toplevel False False (MN 0 "tac") (PRefl (FC "prf" 0))
387trivial ist = try (do elab ist toplevel False False (MN 0 "tac") (PRefl (FC "prf" 0))
361 return ())
388 return ())