-\section[GHCmain]{Module @GHCmain@}
+%
+% (c) The AQUA Project, Glasgow University, 1994-1997
+%
-This is the mainPrimIO that must be used for Haskell~1.3.
+\section[GHCmain]{Module @GHCmain@}
\begin{code}
-module GHCmain( mainPrimIO ) where
+module GHCmain( mainIO ) where
import Prelude
-import qualified Main -- for type of "Main.main"
-import IOBase
-import STBase
+import {-# SOURCE #-} qualified Main -- for type of "Main.main"
\end{code}
\begin{code}
-mainPrimIO = ST $ \ s ->
- case Main.main of { IO (ST main_guts) ->
- case main_guts s of { (result, s2@(S# _)) ->
- case result of
- Right () -> ( (), s2 )
- Left err -> error ("I/O error: "++showsPrec 0 err "\n")
- }}
+mainIO :: IO () -- It must be of type (IO t) because that's what
+ -- the RTS expects. GHC doesn't check this, so
+ -- make sure this type signature stays!
+mainIO = catch Main.main (\err -> error ("I/O error: "++showsPrec 0 err "\n"))
\end{code}
-
-OLD COMMENT:
-
-Nota Bene! @mainIO@ is written as an explicit function, rather than
-by saying: @mainIO = requestToIO main@ so that the code generator
-recognises @mainIO@ as a {\em function} (hence HNF, hence not
-updatable), rather than a zero-arity CAF (hence updatable). If it is
-updated, then we have a mega-space leak, because the entire action
-(@requestToIO main@) is retained indefinitely.
-
-(This doesn't waste work because @mainIO@ is only used once.)