[project @ 2000-03-02 14:20:28 by panne]
[ghc-hetmet.git] / ghc / lib / std / Prelude.lhs
index 401e5ca..01e82b3 100644 (file)
@@ -43,9 +43,11 @@ 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(..),
@@ -75,7 +77,8 @@ import PrelList
 import PrelRead
 import PrelEnum
 import PrelNum
-import PrelNumExtra
+import PrelReal
+import PrelFloat
 import PrelTup
 import PrelMaybe
 import PrelShow
@@ -99,6 +102,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.
 
@@ -123,3 +132,39 @@ product    l       = prod l 1
     prod (x:xs) a = prod xs (a*x)
 #endif
 \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}