@@ -321,6 +321,9 @@ elab ist info pattern tcgen fn tm
321321 False -> return failed
322322 elabArgs ina failed r ns args
323323
324+-- For every alternative, look at the function at the head. Automatically resolve
325+-- any nested alternatives where that function is also at the head
326+
324327pruneAlt :: [PTerm] -> [PTerm]
325328pruneAlt xs = map prune xs
326329 where
@@ -328,10 +331,17 @@ pruneAlt xs = map prune xs
328331 = PApp fc1 (PRef fc2 f) (fmap (fmap (choose f)) as)
329332 prune t = t
330333
331− choose f (PAlternative as) = PAlternative (filter (headIs f) as)
334+ choose f (PAlternative as)
335+ = let as' = fmap (choose f) as
336+ fs = filter (headIs f) as' in
337+ case fs of
338+ [a] -> a
339+ _ -> PAlternative as'
340+ choose f (PApp fc f' as) = PApp fc (choose f f') (fmap (fmap (choose f)) as)
332341 choose f t = t
333342
334343 headIs f (PApp _ (PRef _ f') _) = f == f'
344+ headIs f (PApp _ f' _) = headIs f f'
335345 headIs f _ = True -- keep if it's not an application
336346
337347trivial :: IState -> ElabD ()