X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FNum.lhs;h=b5e27a8c77ffaf1593807dfd7561c2d346e3a6a6;hb=b1f2e321ceac8fcfc1f0756e2f5c2585fbd00b3c;hp=a0c61e7ba76c1616dd47bba66ab181c6fb1a41c9;hpb=789216806265506d3b4637b3b22eb5a46eb5f8f8;p=ghc-base.git diff --git a/GHC/Num.lhs b/GHC/Num.lhs index a0c61e7..b5e27a8 100644 --- a/GHC/Num.lhs +++ b/GHC/Num.lhs @@ -1,5 +1,5 @@ \begin{code} -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude #-} ----------------------------------------------------------------------------- -- | -- Module : GHC.Num @@ -23,11 +23,11 @@ #error Please define LEFTMOST_BIT to be 2^(SIZEOF_HSWORD*8-1) #endif +-- #hide module GHC.Num where import {-# SOURCE #-} GHC.Err import GHC.Base -import GHC.List import GHC.Enum import GHC.Show @@ -45,15 +45,37 @@ default () -- Double isn't available yet, %********************************************************* \begin{code} +-- | Basic numeric class. +-- +-- Minimal complete definition: all except 'negate' or @(-)@ class (Eq a, Show a) => Num a where (+), (-), (*) :: a -> a -> a + -- | Unary negation. negate :: a -> a - abs, signum :: a -> a + -- | Absolute value. + abs :: a -> a + -- | Sign of a number. + -- The functions 'abs' and 'signum' should satisfy the law: + -- + -- > abs x * signum x == x + -- + -- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero) + -- or @1@ (positive). + signum :: a -> a + -- | Conversion from an 'Integer'. + -- An integer literal represents the application of the function + -- 'fromInteger' to the appropriate value of type 'Integer', + -- so such literals have type @('Num' a) => a@. fromInteger :: Integer -> a x - y = x + negate y negate x = 0 - x +-- | the same as @'flip' ('-')@. +-- +-- Because @-@ is treated specially in the Haskell grammar, +-- @(-@ /e/@)@ is not a section, but an application of prefix negation. +-- However, @('subtract'@ /exp/@)@ is equivalent to the disallowed section. {-# INLINE subtract #-} subtract :: (Num a) => a -> a -> a subtract x y = y - x @@ -79,15 +101,9 @@ instance Num Int where | otherwise = 1 fromInteger = integer2Int -\end{code} - - -\begin{code} --- These can't go in GHC.Base with the defn of Int, because --- we don't have pairs defined at that time! quotRemInt :: Int -> Int -> (Int, Int) -a@(I# _) `quotRemInt` b@(I# _) = (a `quotInt` b, a `remInt` b) +quotRemInt a@(I# _) b@(I# _) = (a `quotInt` b, a `remInt` b) -- OK, so I made it a little stricter. Shoot me. (WDP 94/10) divModInt :: Int -> Int -> (Int, Int) @@ -95,7 +111,6 @@ divModInt x@(I# _) y@(I# _) = (x `divInt` y, x `modInt` y) -- Stricter. Sorry if you don't like it. (WDP 94/10) \end{code} - %********************************************************* %* * \subsection{The @Integer@ type}