@@ -410,31 +410,43 @@ recoverableCoverage _ _ = False
411checkRec :: Term -> Term -> State [(Name, Term)] Bool
411checkRec :: Term -> Term -> State [(Name, Term)] Bool
412checkRec (P Bound x _) tm
412checkRec (P Bound x _) tm
413− | (P yt _ _, _) <- unApply tm,
414− conType yt = do nmap <- get
413+ | isCon tm = do nmap <- get
415− case lookup x nmap of
414+ case lookup x nmap of
416− Nothing -> do put ((x, tm) : nmap)
415+ Nothing -> do put ((x, tm) : nmap)
417− return True
416+ return True
418− Just y' -> checkRec tm y'
417+ Just y' -> checkRec tm y'
420+ | (P yt _ _, _) <- unApply tm,
422+ isCon (Constant _) = True
420 conType (DCon _ _ _) = True
425 conType (DCon _ _ _) = True
421 conType (TCon _ _) = True
426 conType (TCon _ _) = True
422 conType _ = False
427 conType _ = False
424checkRec tm (P Bound y _)
429checkRec tm (P Bound y _)
425− | (P xt _ _, _) <- unApply tm,
426− conType xt = do nmap <- get
430+ | isCon tm = do nmap <- get
427− case lookup y nmap of
431+ case lookup y nmap of
428− Nothing -> do put ((y, tm) : nmap)
432+ Nothing -> do put ((y, tm) : nmap)
429− return True
433+ return True
430− Just x' -> checkRec tm x'
434+ Just x' -> checkRec tm x'
437+ | (P yt _ _, _) <- unApply tm,
439+ isCon (Constant _) = True
432 conType (DCon _ _ _) = True
442 conType (DCon _ _ _) = True
433 conType (TCon _ _) = True
443 conType (TCon _ _) = True
434 conType _ = False
444 conType _ = False
436checkRec (App _ f a) p@(P _ _ _) = checkRec f p
446checkRec (App _ f a) p@(P _ _ _) = checkRec f p
447+checkRec (App _ f a) p@(Constant _) = checkRec f p
437checkRec p@(P _ _ _) (App _ f a) = checkRec p f
448checkRec p@(P _ _ _) (App _ f a) = checkRec p f
449+checkRec p@(Constant _) (App _ f a) = checkRec p f
438checkRec fa@(App _ _ _) fa'@(App _ _ _)
450checkRec fa@(App _ _ _) fa'@(App _ _ _)
439 | (f, as) <- unApply fa,
451 | (f, as) <- unApply fa,
440 (f', as') <- unApply fa'
452 (f', as') <- unApply fa'
@@ -454,6 +466,7 @@ checkRec fa@(App _ _ _) fa'@(App _ _ _)
454 return (aok && asok)
466 return (aok && asok)
455 conType (P (DCon _ _ _) _ _) = True
467 conType (P (DCon _ _ _) _ _) = True
456 conType (P (TCon _ _) _ _) = True
468 conType (P (TCon _ _) _ _) = True
469+ conType (Constant _) = True
457 conType _ = False
470 conType _ = False
459checkRec (P xt x _) (P yt y _)
472checkRec (P xt x _) (P yt y _)
@@ -469,4 +482,8 @@ checkRec (P xt x _) (P yt y _)
469 | Bound <- x = True
482 | Bound <- x = True
470 | Bound <- y = True
483 | Bound <- y = True
471 | otherwise = False -- name is different, unrecoverable
484 | 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
472checkRec _ _ = return False
489checkRec _ _ = return False