-This grimy bit of code is for digging out the IOok constructor from an
-application of the the IO type. The constructor is needed for
-wrapping the result of a _ccall_. The alternative is to wire-in IO,
-which brings a whole heap of junk with it.
-
-If the representation of IO changes, this will probably have to be
-brought in line with the new definition.
-
-newtype IO a = IO (State# RealWorld -> IOResult a)
-
-the constructor IO has type (State# RealWorld -> IOResult a) -> IO a
-
-\begin{code}
-getIoOkDataCon :: Type -- IO t
- -> (Id, Id, Type) -- Returns (IOok, IO, t)
-
-getIoOkDataCon io_ty
- = let
- Just (ioTyCon, [t]) = splitTyConApp_maybe io_ty
- [ioDataCon] = tyConDataCons ioTyCon
- ioDataConTy = idType ioDataCon
- (_, ioDataConTy') = splitForAllTys ioDataConTy
- ([arg_ty], _) = splitFunTys ioDataConTy'
- (_, io_result_ty) = splitFunTys arg_ty
- Just (io_result_tycon, _) = splitTyConApp_maybe io_result_ty
- [ioOkDataCon,ioFailDataCon] = tyConDataCons io_result_tycon
- in
- (ioOkDataCon, ioDataCon, t)