module Prelude (
- -- Everything from these modules
- module PrelList,
+ -- 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),
Either(..),
Ordering(..),
Char, String, Int, Integer, Float, Double, IO,
- Ratio, Rational,
+ Rational,
[]((:), []),
module PrelTup,
Ord(..),
Enum(..),
Bounded(..),
- Num((+), (-), (*), negate, abs, signum, fromInteger, fromInt{-glaExt-}),
+ Num((+), (-), (*), negate, abs, signum, fromInteger),
+ -- The fromInt method is exposed only by GlaExts
Real(..),
- Integral(quot, rem, div, mod, quotRem, divMod, toInteger, toInt{-partain-}),
+ Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
+ -- The toInt method is exposed only by GlaExts
Fractional(..),
Floating(..),
RealFrac(..),
RealFloat(..),
- -- From Monad
+ -- Monad stuff, from PrelBase, and defined here
Monad(..),
Functor(..),
mapM, mapM_, sequence, sequence_, (=<<),
import PrelBase
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 PrelEither
-import PrelBounded
+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
\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.
+
+\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}
+
+
+%*********************************************************
+%* *
+\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}
+%* *
+%*********************************************************
+
+\begin{code}
+{-# SPECIALIZE fromIntegral ::
+ Int -> Rational,
+ Integer -> Rational,
+ Int -> Int,
+ Int -> Integer,
+ Int -> Float,
+ Int -> Double,
+ Integer -> Int,
+ Integer -> Integer,
+ Integer -> Float,
+ Integer -> Double #-}
+fromIntegral :: (Integral a, Num b) => a -> b
+fromIntegral = fromInteger . toInteger
+
+{-# SPECIALIZE realToFrac ::
+ Double -> Rational,
+ Rational -> Double,
+ Float -> Rational,
+ Rational -> Float,
+ Rational -> Rational,
+ Double -> Double,
+ Double -> Float,
+ Float -> Float,
+ Float -> Double #-}
+realToFrac :: (Real a, Fractional b) => a -> b
+realToFrac = fromRational . toRational
+\end{code}