checkRec tm (P Bound y _)
   | isCon tm = do nmap <- get
                   case lookup y nmap of
                        Nothing -> do put ((y, tm) : nmap)
                                      return True
                        Just x' -> checkRec tm x'
 where
   isCon tm
       | (P yt _ _, _) <- unApply tm,
         conType yt = True
   isCon (Constant _) = True
   isCon _ = False

   conType (DCon _ _ _) = True
   conType (TCon _ _) = True
   conType _ = False
checkRec tm (P Bound y _)
   | isCon tm = do nmap <- get
                   case lookup y nmap of
                        Nothing -> do put ((y, tm) : nmap)
                                      return True
                        Just x' -> checkRec tm x'
 where
   isCon tm
       | (P yt _ _, _) <- unApply tm,
         conType yt = True
   isCon (Constant _) = True
   isCon _ = False

   conType (DCon _ _ _) = True
   conType (TCon _ _) = True
   conType _ = False
checkRec tm (P Bound y _)
   | isCon tm = do nmap <- get
                   case lookup y nmap of
                        Nothing -> do put ((y, tm) : nmap)
                                      return True
                        Just x' -> checkRec tm x'
 where
   isCon tm
       | (P yt _ _, _) <- unApply tm,
         conType yt = True
   isCon (Constant _) = True
   isCon _ = False

   conType (DCon _ _ _) = True
   conType (TCon _ _) = True
   conType _ = False