[project @ 1999-10-22 08:47:39 by sof]
[ghc-hetmet.git] / ghc / lib / std / Prelude.lhs
index 1ba96bb..0b9f102 100644 (file)
@@ -7,118 +7,90 @@ and Prelude.-> (as they are normally). -- SDM 8/10/97
 
 module Prelude (
 
-       -- Everything from these modules
-    module PrelList,
-    module PrelTup,
+       -- Everything corresponding to the Report's PreludeList
+    module PrelList, 
+    lines, words, unlines, unwords,
+    sum, product,
+
+        -- Everything corresponding to the Report's PreludeText
+    ReadS, ShowS,
+    Read(readsPrec, readList),
+    Show(showsPrec, showList, show),
+    reads, shows, read, lex, 
+    showChar, showString, readParen, showParen,
+    
+        -- Everything corresponding to the Report's PreludeIO
+    FilePath, IOError,
+    ioError, userError, catch,
+    putChar, putStr, putStrLn, print,
+    getChar, getLine, getContents, interact,
+    readFile, writeFile, appendFile, readIO, readLn,
 
-       -- From PrelBase
-    (->),
-    Eq(..), 
-    Ord(..), Ordering(..), 
-    Bounded(..), 
-    Enum(..), succ, pred, 
-    Show(..), ShowS, shows, show, showChar, showString, showParen,
-    Eval(..), seq, strict,
-    Bool(..), (&&), (||), not, otherwise,
-    Char, String, Int, Integer, Float, Double, Void,
-    Maybe(..), maybe,
-    Either(..), either,
+    Bool(..),
+    Maybe(..),
+    Either(..),
+    Ordering(..), 
+    Char, String, Int, Integer, Float, Double, IO,
+    Rational,
+    []((:), []),
+    
+    module PrelTup,
+        -- Includes tuple types + fst, snd, curry, uncurry
     ()(..),            -- The unit type
-
+    (->),              -- functions
     
-    id, const, (.), flip, ($), until, asTypeOf, undefined,
-
-       -- From Error
-    error,
+    Eq(..),
+    Ord(..), 
+    Enum(..),
+    Bounded(..), 
+    Num((+), (-), (*), negate, abs, signum, fromInteger),
+       -- The fromInt method is exposed only by GlaExts
+    Real(..),
+    Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
+       -- The toInt method is exposed only by GlaExts
+    Fractional(..),
+    Floating(..),
+    RealFrac(..),
+    RealFloat(..),
 
        -- From Monad
-    Functor(..), Monad(..), MonadZero(..), MonadPlus(..),
-    accumulate, sequence, mapM, mapM_, guard, filter, concat, applyM,
+    Monad(..),
+    Functor(..), 
+    mapM, mapM_, sequence, sequence_, (=<<),
 
-       -- From PrelRead
-    ReadS, Read(readsPrec, readList),
-    reads, read, lex, readParen, 
-
-        -- From IO
-    IO, FilePath, IOError,
-    fail, userError, catch,
-    putChar, putStr, putStrLn, print,
-    getChar, getLine, getContents, interact,
-    readFile, writeFile, appendFile, readIO, readLn,
-
-       -- From PrelNum
-    Ratio, Rational, 
-    (%), numerator, denominator, approxRational,
-
-    Num((+), (-), (*), negate, abs, signum, fromInteger, fromInt{-glaExt-}),
-    Real(toRational),
-    Integral(quot, rem, div, mod, quotRem, divMod, toInteger, toInt{-partain-}),
-    Fractional((/), recip, fromRational),
-    Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
-             asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
-    RealFrac(properFraction, truncate, round, ceiling, floor),
-    RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
-              encodeFloat, exponent, significand, scaleFloat, isNaN,
-              isInfinite, isDenormalized, isIEEE, isNegativeZero),
+    maybe, either,
+    (&&), (||), not, otherwise,
     subtract, even, odd, gcd, lcm, (^), (^^), 
-    fromIntegral, fromRealFrac, atan2
+    fromIntegral, realToFrac,
+    --exported by PrelTup: fst, snd, curry, uncurry,
+    id, const, (.), flip, ($), until,
+    asTypeOf, error, undefined,
+    seq, ($!)
+
   ) where
 
 import PrelBase
 import PrelList
+#ifndef USE_REPORT_PRELUDE
+     hiding ( takeUInt_append )
+#endif
 import PrelRead
+import PrelEnum
 import PrelNum
+import PrelNumExtra
 import PrelTup
 import PrelMaybe
-import PrelEither
-import PrelBounded
+import PrelShow
+import PrelConc
 import Monad
 import Maybe
-import PrelErr   ( error, seqError )
-import IO  ( IO, FilePath, IOError,
-            fail, userError, catch,
-            putChar, putStr, putStrLn, print,
-            getChar, getLine, getContents, interact,
-            readFile, writeFile, appendFile, readIO, readLn
-          )
-
-{- Declared elsewhere:
-PrelBase: infixr 9 .
-PrelNum:  infixr 8 ^, ^^, **
-PrelBase: infixl *
-PrelNum:  infixl 7 /, %, `quot`, `rem`, `div`, `mod`
-PrelBase: infixl 6 +, -
-PrelBase: infixr 5 :, ++
-PrelBase: infix  4 ==, /=, <. <=, >=, >
-PrelBase: infixr 3 &&
-PrelBase: infixr 2 ||
-PrelBase: infixl >>, >>=
-PrelBase: infixr $
--}
-infixr 0 `seq`
-
-
--- These can't conveniently be defined in PrelBase because they use numbers,
--- or I/O, so here's a convenient place to do them.
-
-strict      :: Eval a => (a -> b) -> a -> b
-strict f x  = x `seq` f x
-
-
--- "seq" is defined a bit wierdly (see below)
---
--- The reason for the strange "0# -> parError" case is that
--- it fools the compiler into thinking that seq is non-strict in
--- its second argument (even if it inlines seq at the call site).
--- If it thinks seq is strict in "y", then it often evaluates
--- "y" before "x", which is totally wrong.  
---
--- Just before converting from Core to STG there's a bit of magic
--- that recognises the seq# and eliminates the duff case.
-
-{-# INLINE seq  #-}
-seq :: Eval a => a -> b -> b
-seq  x y = case (seq#  x) of { 0# -> seqError; _ -> y }
+import PrelErr   ( error )
+import IO
+
+infixr 0 $!
+
+($!)    :: (a -> b) -> a -> b
+f $! x  = x `seq` f x
 
 -- It is expected that compilers will recognize this and insert error
 -- messages which are more appropriate to the context in which undefined 
@@ -129,4 +101,27 @@ undefined               =  error "Prelude.undefined"
 \end{code}
 
 
+List sum and product are defined here because PrelList is too far
+down the compilation chain to "see" the Num class.
 
+\begin{code}
+-- sum and product compute the sum or product of a finite list of numbers.
+{-# SPECIALISE sum     :: [Int] -> Int #-}
+{-# SPECIALISE sum     :: [Integer] -> Integer #-}
+{-# SPECIALISE product :: [Int] -> Int #-}
+{-# SPECIALISE product :: [Integer] -> Integer #-}
+sum, product            :: (Num a) => [a] -> a
+#ifdef USE_REPORT_PRELUDE
+sum                     =  foldl (+) 0  
+product                 =  foldl (*) 1
+#else
+sum    l       = sum' l 0
+  where
+    sum' []     a = a
+    sum' (x:xs) a = sum' xs (a+x)
+product        l       = prod l 1
+  where
+    prod []     a = a
+    prod (x:xs) a = prod xs (a*x)
+#endif
+\end{code}