@@ -410,31 +410,43 @@ recoverableCoverage _ _ = False
410410-- with
411411checkRec :: Term -> Term -> State [(Name, Term)] Bool
412412checkRec (P Bound x _) tm
413− | (P yt _ _, _) <- unApply tm,
414− conType yt = do nmap <- get
415− case lookup x nmap of
416− Nothing -> do put ((x, tm) : nmap)
417− return True
418− Just y' -> checkRec tm y'
413+ | isCon tm = do nmap <- get
414+ case lookup x nmap of
415+ Nothing -> do put ((x, tm) : nmap)
416+ return True
417+ Just y' -> checkRec tm y'
419418 where
419+ isCon tm
420+ | (P yt _ _, _) <- unApply tm,
421+ conType yt = True
422+ isCon (Constant _) = True
423+ isCon _ = False
424+
420425 conType (DCon _ _ _) = True
421426 conType (TCon _ _) = True
422427 conType _ = False
423428
424429checkRec tm (P Bound y _)
425− | (P xt _ _, _) <- unApply tm,
426− conType xt = do nmap <- get
427− case lookup y nmap of
428− Nothing -> do put ((y, tm) : nmap)
429− return True
430− Just x' -> checkRec tm x'
430+ | isCon tm = do nmap <- get
431+ case lookup y nmap of
432+ Nothing -> do put ((y, tm) : nmap)
433+ return True
434+ Just x' -> checkRec tm x'
431435 where
436+ isCon tm
437+ | (P yt _ _, _) <- unApply tm,
438+ conType yt = True
439+ isCon (Constant _) = True
440+ isCon _ = False
441+
432442 conType (DCon _ _ _) = True
433443 conType (TCon _ _) = True
434444 conType _ = False
435445
436446checkRec (App _ f a) p@(P _ _ _) = checkRec f p
447+checkRec (App _ f a) p@(Constant _) = checkRec f p
437448checkRec p@(P _ _ _) (App _ f a) = checkRec p f
449+checkRec p@(Constant _) (App _ f a) = checkRec p f
438450checkRec fa@(App _ _ _) fa'@(App _ _ _)
439451 | (f, as) <- unApply fa,
440452 (f', as') <- unApply fa'
@@ -454,6 +466,7 @@ checkRec fa@(App _ _ _) fa'@(App _ _ _)
454466 return (aok && asok)
455467 conType (P (DCon _ _ _) _ _) = True
456468 conType (P (TCon _ _) _ _) = True
469+ conType (Constant _) = True
457470 conType _ = False
458471
459472checkRec (P xt x _) (P yt y _)
@@ -469,4 +482,8 @@ checkRec (P xt x _) (P yt y _)
469482 | Bound <- x = True
470483 | Bound <- y = True
471484 | otherwise = False -- name is different, unrecoverable
485+-- A function reference against a constant might be recoverable if we get to
486+-- reduce the function
487+checkRec (P Ref _ _) (Constant _) = return True
488+checkRec (Constant _) (P Ref _ _) = return True
472489checkRec _ _ = return False