[project @ 1997-08-25 22:43:11 by sof]
[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 Prelude
9 import {-# SOURCE #-} qualified Main    -- for type of "Main.main"
10 import IOBase
11 import STBase
12 \end{code}
13
14 \begin{code}
15 mainPrimIO = ST $ \ s ->
16     case Main.main   of { IO (ST main_guts) ->
17     case main_guts s of { (result, s2@(S# _)) ->
18     case result   of
19       Right ()  -> ( (), s2 )
20       Left  err -> error ("I/O error: "++showsPrec 0 err "\n")
21     }}
22 \end{code}
23
24 OLD COMMENT:
25
26 Nota Bene!  @mainIO@ is written as an explicit function, rather than
27 by saying: @mainIO = requestToIO main@ so that the code generator
28 recognises @mainIO@ as a {\em function} (hence HNF, hence not
29 updatable), rather than a zero-arity CAF (hence updatable).  If it is
30 updated, then we have a mega-space leak, because the entire action
31 (@requestToIO main@) is retained indefinitely.
32
33 (This doesn't waste work because @mainIO@ is only used once.)