+tcSplitIOType_maybe :: Type -> Maybe (TyCon, Type)
+-- (isIOType t) returns (Just (IO,t')) if t is of the form (IO t'), or
+-- some newtype wrapping thereof
+-- returns Nothing otherwise
+tcSplitIOType_maybe ty
+ | Just (io_tycon, [io_res_ty]) <- tcSplitTyConApp_maybe ty,
+ -- This split absolutely has to be a tcSplit, because we must
+ -- see the IO type; and it's a newtype which is transparent to splitTyConApp.
+ io_tycon `hasKey` ioTyConKey
+ = Just (io_tycon, io_res_ty)
+
+ | Just ty' <- coreView ty -- Look through non-recursive newtypes
+ = tcSplitIOType_maybe ty'
+
+ | otherwise
+ = Nothing
+