2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
4 \section[MainMonad]{I/O monad used in @Main@ module of the compiler}
7 #include "HsVersions.h"
14 -- foldlMn, INLINEd at its two (important) uses...
20 fopen, fclose, fwrite, _FILE(..),
23 IF_ATTACK_PRAGMAS(COMMA getArgsPrimIO)
24 IF_ATTACK_PRAGMAS(COMMA appendFilePrimIO)
25 IF_ATTACK_PRAGMAS(COMMA appendChanPrimIO)
26 IF_ATTACK_PRAGMAS(COMMA readChanPrimIO)
27 IF_ATTACK_PRAGMAS(COMMA mkSplitUniqSupply) -- profiling only, really
38 import UniqSupply ( mkSplitUniqSupply, UniqSupply )
40 infixr 9 `thenMn` -- right-associative, please
44 A value of type @MainIO a@ represents an I/O-performing computation
45 returning a value of type @a@. It is a function from the whole list
46 of responses-to-the-rest-of-the-program, to a triple consisting of:
49 the value of type @a@;
51 a function which prefixes the requests for the computation to
52 the front of a supplied list of requests; using a function here
53 avoids an expensive append operation in @thenMn@;
55 the depleted list of responses.
59 returnMn :: a -> MainIO a
60 thenMn :: MainIO a -> (a -> MainIO b) -> MainIO b
61 thenMn_ :: MainIO a -> MainIO b -> MainIO b
64 readMn :: String{-channel-} -> MainIO String
65 writeMn :: String{-channel-} -> String -> MainIO ()
67 readMn :: Handle -> MainIO String
68 writeMn :: Handle -> String -> MainIO ()
71 getArgsMn :: MainIO [String]
73 :: Char -> MainIO UniqSupply
74 exitMn :: Int -> MainIO ()
76 {-# INLINE returnMn #-}
78 {-# INLINE thenMn_ #-}
82 then error "Compilation had errors\n"
87 type MainIO a = PrimIO a
89 returnMn = returnPrimIO
93 readMn chan = readChanPrimIO chan
94 writeMn chan str = appendChanPrimIO chan str
95 getArgsMn = getArgsPrimIO
97 getSplitUniqSupplyMn char = mkSplitUniqSupply char
107 readMn chan = hGetContents chan
108 writeMn chan str = hPutStr chan str
111 getSplitUniqSupplyMn char
112 = mkSplitUniqSupply char `thenPrimIO` \ us ->