88de160de51cd1dbaf1d2a115e5ad470a315b1e8
[ghc-hetmet.git] / ghc / lib / ghc / GHCmain.lhs
1 \section[GHCmain]{Module @GHCmain@}
2
3 This is the mainPrimIO that must be used for Haskell~1.3.
4
5 \begin{code}
6 module GHCmain( mainPrimIO ) where
7
8 import qualified Main   -- for type of "Main.main"
9 import IOBase
10 import STBase
11 \end{code}
12
13 \begin{code}
14 mainPrimIO = ST $ \ s ->
15     case Main.main   of { IO (ST main_guts) ->
16     case main_guts s of { (result, s2@(S# _)) ->
17     case result   of
18       Right ()  -> ( (), s2 )
19       Left  err -> error ("I/O error: "++showsPrec 0 err "\n")
20     }}
21 \end{code}
22
23 OLD COMMENT:
24
25 Nota Bene!  @mainIO@ is written as an explicit function, rather than
26 by saying: @mainIO = requestToIO main@ so that the code generator
27 recognises @mainIO@ as a {\em function} (hence HNF, hence not
28 updatable), rather than a zero-arity CAF (hence updatable).  If it is
29 updated, then we have a mega-space leak, because the entire action
30 (@requestToIO main@) is retained indefinitely.
31
32 (This doesn't waste work because @mainIO@ is only used once.)