module GHC.Num (module GHC.Num, module GHC.Integer) where import GHC.Base import GHC.Integer infixl 7 * infixl 6 +, default ()\end{code} %********************************************************* %* * \subsection{Standard numeric class} %* * %********************************************************* \begin{code}
class Num a where (+), (), (*) :: a -> a -> a negate :: a -> a abs :: a -> a signum :: a -> a fromInteger :: Integer -> a x y = x + negate y negate x = 0 x subtract :: (Num a) => a -> a -> a subtract x y = y x\end{code} %********************************************************* %* * \subsection{Instances for @Int@} %* * %********************************************************* \begin{code}
instance Num Int where (+) = plusInt () = minusInt negate = negateInt (*) = timesInt abs n = if n `geInt` 0 then n else negateInt n signum n | n `ltInt` 0 = negateInt 1 | n `eqInt` 0 = 0 | otherwise = 1 fromInteger i = I# (integerToInt i) quotRemInt :: Int -> Int -> (Int, Int) quotRemInt a@(I# _) b@(I# _) = (a `quotInt` b, a `remInt` b) divModInt :: Int -> Int -> (Int, Int) divModInt x@(I# _) y@(I# _) = (x `divInt` y, x `modInt` y)\end{code} %********************************************************* %* * \subsection{The @Integer@ instances for @Num@} %* * %********************************************************* \begin{code}
instance Num Integer where (+) = plusInteger () = minusInteger (*) = timesInteger negate = negateInteger fromInteger x = x abs = absInteger signum = signumInteger\end{code}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4