[project @ 2000-04-10 16:49:15 by sewardj]
[ghc-hetmet.git] / ghc / lib / std / Prelude.lhs
index 01e82b3..01e55fc 100644 (file)
@@ -3,7 +3,7 @@ special names such as () and -> shouldn't be resolved to Prelude.()
 and Prelude.-> (as they are normally). -- SDM 8/10/97
 
 \begin{code}
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS -fcompiling-prelude -fno-implicit-prelude #-}
 
 module Prelude (
 
@@ -53,7 +53,7 @@ module Prelude (
     RealFrac(..),
     RealFloat(..),
 
-       -- From Monad
+       -- Monad stuff, from PrelBase, and defined here
     Monad(..),
     Functor(..), 
     mapM, mapM_, sequence, sequence_, (=<<),
@@ -74,6 +74,9 @@ import PrelList
 #ifndef USE_REPORT_PRELUDE
      hiding ( takeUInt_append )
 #endif
+import PrelIO
+import PrelIOBase
+import PrelException
 import PrelRead
 import PrelEnum
 import PrelNum
@@ -83,13 +86,20 @@ 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
 
@@ -136,6 +146,37 @@ product    l       = prod l 1
 
 %*********************************************************
 %*                                                     *
+\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}
+
+
+%*********************************************************
+%*                                                     *
 \subsection{Coercions}
 %*                                                     *
 %*********************************************************
@@ -168,3 +209,4 @@ fromIntegral        =  fromInteger . toInteger
 realToFrac     :: (Real a, Fractional b) => a -> b
 realToFrac     =  fromRational . toRational
 \end{code}
+