X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FPrelude.lhs;h=01e55fc8e12a5ac6b0f1b7434058c87106623c43;hb=a103a9dc0de992716e62c30d7ac81c0bc0dbcdc5;hp=cf2fb00ed92ac032b4328e4d3941327ee314dafe;hpb=733d33624889b086ba08d2317fdb99384cf82f51;p=ghc-hetmet.git diff --git a/ghc/lib/std/Prelude.lhs b/ghc/lib/std/Prelude.lhs index cf2fb00..01e55fc 100644 --- a/ghc/lib/std/Prelude.lhs +++ b/ghc/lib/std/Prelude.lhs @@ -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 ( @@ -43,15 +43,17 @@ module Prelude ( 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_, (=<<), @@ -68,22 +70,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 +112,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 +142,71 @@ 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} + + +%********************************************************* +%* * +\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} +