tyTyCons :: Type -> Set TyCon
tyTyCons = go . expandTypeSynonyms
  where
    go t0
        | Just (t1,t2) <- splitFunTy_maybe t0    = S.union (go t1) (go t2)
        | Just (tc,ts) <- splitTyConApp_maybe t0 = S.insert tc (S.unions (map go ts))
        | Just (_,t) <- splitForAllTy_maybe t0   = go t
        | otherwise                              = S.empty
tyTyCons :: Type -> Set TyCon
tyTyCons = go . expandTypeSynonyms
  where
    go t0
        | Just (t1,t2) <- splitFunTy_maybe t0    = S.union (go t1) (go t2)
        | Just (tc,ts) <- splitTyConApp_maybe t0 = S.insert tc (S.unions (map go ts))
        | Just (_,t) <- splitForAllTy_maybe t0   = go t
        | otherwise                              = S.empty
tyTyCons = go . expandTypeSynonyms
  where
    go t0
        | Just (t1,t2) <- splitFunTy_maybe t0    = S.union (go t1) (go t2)
        | Just (tc,ts) <- splitTyConApp_maybe t0 = S.insert tc (S.unions (map go ts))
        | Just (_,t) <- splitForAllTy_maybe t0   = go t
        | otherwise                              = S.empty