1 We add the option -fno-implicit-prelude here to tell the reader that
2 special names such as () and -> shouldn't be resolved to Prelude.()
3 and Prelude.-> (as they are normally). -- SDM 8/10/97
6 {-# OPTIONS -fno-implicit-prelude #-}
10 -- Everything corresponding to the Report's PreludeList
12 lines, words, unlines, unwords,
15 -- Everything corresponding to the Report's PreludeText
17 Read(readsPrec, readList),
18 Show(showsPrec, showList, show),
19 reads, shows, read, lex,
20 showChar, showString, readParen, showParen,
22 -- Everything corresponding to the Report's PreludeIO
24 ioError, userError, catch,
25 putChar, putStr, putStrLn, print,
26 getChar, getLine, getContents, interact,
27 readFile, writeFile, appendFile, readIO, readLn,
33 Char, String, Int, Integer, Float, Double, IO,
38 -- Includes tuple types + fst, snd, curry, uncurry
39 ()(..), -- The unit type
46 Num((+), (-), (*), negate, abs, signum, fromInteger),
47 -- The fromInt method is exposed only by GlaExts
49 Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
50 -- The toInt method is exposed only by GlaExts
56 -- Monad stuff, from PrelBase, and defined here
59 mapM, mapM_, sequence, sequence_, (=<<),
62 (&&), (||), not, otherwise,
63 subtract, even, odd, gcd, lcm, (^), (^^),
64 fromIntegral, realToFrac,
65 --exported by PrelTup: fst, snd, curry, uncurry,
66 id, const, (.), flip, ($), until,
67 asTypeOf, error, undefined,
74 #ifndef USE_REPORT_PRELUDE
75 hiding ( takeUInt_append )
89 import PrelErr ( error )
96 %*********************************************************
98 \subsection{Miscellaneous functions}
100 %*********************************************************
103 ($!) :: (a -> b) -> a -> b
106 -- It is expected that compilers will recognize this and insert error
107 -- messages which are more appropriate to the context in which undefined
111 undefined = error "Prelude.undefined"
115 %*********************************************************
117 \subsection{List sum and product}
119 %*********************************************************
121 List sum and product are defined here because PrelList is too far
122 down the compilation chain to "see" the Num class.
125 -- sum and product compute the sum or product of a finite list of numbers.
126 {-# SPECIALISE sum :: [Int] -> Int #-}
127 {-# SPECIALISE sum :: [Integer] -> Integer #-}
128 {-# SPECIALISE product :: [Int] -> Int #-}
129 {-# SPECIALISE product :: [Integer] -> Integer #-}
130 sum, product :: (Num a) => [a] -> a
131 #ifdef USE_REPORT_PRELUDE
133 product = foldl (*) 1
138 sum' (x:xs) a = sum' xs (a+x)
142 prod (x:xs) a = prod xs (a*x)
147 %*********************************************************
149 \subsection{Prelude monad functions}
151 %*********************************************************
154 {-# SPECIALISE (=<<) :: (a -> [b]) -> [a] -> [b] #-}
155 (=<<) :: Monad m => (a -> m b) -> m a -> m b
158 sequence :: Monad m => [m a] -> m [a]
159 {-# INLINE sequence #-}
160 sequence ms = foldr k (return []) ms
162 k m m' = do { x <- m; xs <- m'; return (x:xs) }
164 sequence_ :: Monad m => [m a] -> m ()
165 {-# INLINE sequence_ #-}
166 sequence_ ms = foldr (>>) (return ()) ms
168 mapM :: Monad m => (a -> m b) -> [a] -> m [b]
170 mapM f as = sequence (map f as)
172 mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
174 mapM_ f as = sequence_ (map f as)
178 %*********************************************************
180 \subsection{Coercions}
182 %*********************************************************
186 "fromIntegral/Int->Int" fromIntegral = id :: Int -> Int
187 "fromIntegral/Integer->Integer" fromIntegral = id :: Integer -> Integer
188 "fromIntegral/Int->Integer" fromIntegral = int2Integer
189 "fromIntegral/Integer->Int" fromIntegral = integer2Int
190 "fromIntegral/Int->Rational" forall n . fromIntegral n = int2Integer n :% 1
191 "fromIntegral/Integer->Rational" forall n . fromIntegral n = n :% (1 :: Integer)
192 "fromIntegral/Int->Float" fromIntegral = int2Float
193 "fromIntegral/Int->Double" fromIntegral = int2Double
194 "fromIntegral/Integer->Float" forall n . fromIntegral n = encodeFloat n 0 :: Float
195 "fromIntegral/Integer->Double" forall n . fromIntegral n = encodeFloat n 0 :: Double
197 fromIntegral :: (Integral a, Num b) => a -> b
198 fromIntegral = fromInteger . toInteger
201 "realToFrac/Float->Double" realToFrac = floatToDouble
202 "realToFrac/Double->Float" realToFrac = doubleToFloat
203 "realToFrac/Float->Float" realToFrac = id :: Float -> Float
204 "realToFrac/Double->Double" realToFrac = id :: Double -> Double
205 "realToFrac/Rational->Rational" realToFrac = id :: Rational -> Rational
206 "realToFrac/Float->Rational" realToFrac = rf2rat :: Float -> Rational
207 "realToFrac/Double->Rational" realToFrac = rf2rat :: Double -> Rational
208 "realToFrac/Rational->Float" realToFrac = fromRat :: Rational -> Float
209 "realToFrac/Rational->Double" realToFrac = fromRat :: Rational -> Double
211 realToFrac :: (Real a, Fractional b) => a -> b
212 realToFrac = fromRational . toRational
214 doubleToFloat :: Double -> Float
215 doubleToFloat (D# d) = F# (double2Float# d)
217 floatToDouble :: Float -> Double
218 floatToDouble (F# f) = D# (float2Double# f)
220 {-# SPECIALIZE rf2rat ::
224 rf2rat :: RealFloat a => a -> Rational
225 rf2rat x = if n >= 0 then (m * (b ^ n)) :% 1 else m :% (b ^ (-n))
226 where (m,n) = decodeFloat x