[project @ 2001-03-23 16:36:20 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / Prelude.lhs
index cf2fb00..116c466 100644 (file)
@@ -1,3 +1,11 @@
+% ------------------------------------------------------------------------------
+% $Id: Prelude.lhs,v 1.25 2001/02/28 00:01:03 qrczak Exp $
+%
+% (c) The University of Glasgow, 1992-2000
+%
+
+\section[Prelude]{Module @Prelude@}
+
 We add the option -fno-implicit-prelude here to tell the reader that
 special names such as () and -> shouldn't be resolved to Prelude.()
 and Prelude.-> (as they are normally). -- SDM 8/10/97
@@ -43,15 +51,15 @@ module Prelude (
     Ord(..), 
     Enum(..),
     Bounded(..), 
-    Num((+), (-), (*), negate, abs, signum, fromInteger, fromInt{-glaExt-}),
+    Num(..),
     Real(..),
-    Integral(quot, rem, div, mod, quotRem, divMod, toInteger, toInt{-partain-}),
+    Integral(..),
     Fractional(..),
     Floating(..),
     RealFrac(..),
     RealFloat(..),
 
-       -- From Monad
+       -- Monad stuff, from PrelBase, and defined here
     Monad(..),
     Functor(..), 
     mapM, mapM_, sequence, sequence_, (=<<),
@@ -68,22 +76,36 @@ module Prelude (
   ) where
 
 import PrelBase
-import PrelList hiding ( takeUInt_append )
+import PrelList
+#ifndef USE_REPORT_PRELUDE
+     hiding ( takeUInt_append )
+#endif
+import PrelIO
+import PrelIOBase
+import PrelException
 import PrelRead
 import PrelEnum
 import PrelNum
-import PrelNumExtra
+import PrelReal
+import PrelFloat
 import PrelTup
 import PrelMaybe
 import PrelShow
 import PrelConc
-import Monad
-import Maybe
 import PrelErr   ( error )
-import IO
 
+infixr 1 =<<
 infixr 0 $!
+\end{code}
 
+
+%*********************************************************
+%*                                                     *
+\subsection{Miscellaneous functions}
+%*                                                     *
+%*********************************************************
+
+\begin{code}
 ($!)    :: (a -> b) -> a -> b
 f $! x  = x `seq` f x
 
@@ -96,6 +118,12 @@ undefined               =  error "Prelude.undefined"
 \end{code}
 
 
+%*********************************************************
+%*                                                     *
+\subsection{List sum and product}
+%*                                                     *
+%*********************************************************
+
 List sum and product are defined here because PrelList is too far
 down the compilation chain to "see" the Num class.
 
@@ -120,3 +148,34 @@ product    l       = prod l 1
     prod (x:xs) a = prod xs (a*x)
 #endif
 \end{code}
+
+
+%*********************************************************
+%*                                                     *
+\subsection{Prelude monad functions}
+%*                                                     *
+%*********************************************************
+
+\begin{code}
+{-# SPECIALISE (=<<) :: (a -> [b]) -> [a] -> [b] #-}
+(=<<)           :: Monad m => (a -> m b) -> m a -> m b
+f =<< x                = x >>= f
+
+sequence       :: Monad m => [m a] -> m [a] 
+{-# INLINE sequence #-}
+sequence ms = foldr k (return []) ms
+           where
+             k m m' = do { x <- m; xs <- m'; return (x:xs) }
+
+sequence_        :: Monad m => [m a] -> m () 
+{-# INLINE sequence_ #-}
+sequence_ ms     =  foldr (>>) (return ()) ms
+
+mapM            :: Monad m => (a -> m b) -> [a] -> m [b]
+{-# INLINE mapM #-}
+mapM f as       =  sequence (map f as)
+
+mapM_           :: Monad m => (a -> m b) -> [a] -> m ()
+{-# INLINE mapM_ #-}
+mapM_ f as      =  sequence_ (map f as)
+\end{code}