1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
{-# LANGUAGE NoImplicitPrelude #-}
module Compiler.Num where
import Compiler.Error
infixl 7 *
infixl 6 +, -
class Num a where
(+), (-), (*) :: a -> a -> a
negate, abs, signum :: a -> a
fromInteger :: Integer -> a
x - y = x + (negate y)
negate y = 0 - y
foreign import bpcall "Num:" add_char :: Char -> Char -> Char
foreign import bpcall "Num:" subtract_char :: Char -> Char -> Char
foreign import bpcall "Num:" multiply_char :: Char -> Char -> Char
foreign import bpcall "Num:" abs_char :: Char -> Char
foreign import bpcall "Num:" negate_char :: Char -> Char
foreign import bpcall "Num:" signum_char :: Char -> Char
foreign import bpcall "Num:" integerToChar :: Integer -> Char
foreign import bpcall "Num:" intToChar :: Int -> Char
foreign import bpcall "Num:" charToInt :: Char -> Int
instance Num Char where
(+) = add_char
(-) = subtract_char
(*) = multiply_char
abs = abs_char
negate = negate_char
signum = signum_char
fromInteger x = integerToChar x
foreign import bpcall "Num:" add_integer :: Integer -> Integer -> Integer
foreign import bpcall "Num:" subtract_integer :: Integer -> Integer -> Integer
foreign import bpcall "Num:" multiply_integer :: Integer -> Integer -> Integer
foreign import bpcall "Num:" abs_integer :: Integer -> Integer
foreign import bpcall "Num:" negate_integer :: Integer -> Integer
foreign import bpcall "Num:" signum_integer :: Integer -> Integer
instance Num Integer where
(+) = add_integer
(-) = subtract_integer
(*) = multiply_integer
abs = abs_integer
negate = negate_integer
signum = signum_integer
fromInteger x = x
foreign import bpcall "Num:" add_int :: Int -> Int -> Int
foreign import bpcall "Num:" subtract_int :: Int -> Int -> Int
foreign import bpcall "Num:" multiply_int :: Int -> Int -> Int
foreign import bpcall "Num:" abs_int :: Int -> Int
foreign import bpcall "Num:" negate_int :: Int -> Int
foreign import bpcall "Num:" signum_int :: Int -> Int
foreign import bpcall "Num:" integerToInt :: Integer -> Int
instance Num Int where
(+) = add_int
(-) = subtract_int
(*) = multiply_int
abs = abs_int
negate = negate_int
signum = signum_int
fromInteger = integerToInt
foreign import bpcall "Num:" add_double :: Double -> Double -> Double
foreign import bpcall "Num:" subtract_double :: Double -> Double -> Double
foreign import bpcall "Num:" multiply_double :: Double -> Double -> Double
foreign import bpcall "Num:" abs_double :: Double -> Double
foreign import bpcall "Num:" negate_double :: Double -> Double
foreign import bpcall "Num:" signum_double :: Double -> Double
--foreign import bpcall "Num:" intToDouble :: Int -> Double -- used by Enum Double
foreign import bpcall "Num:" integerToDouble :: Integer -> Double
instance Num Double where
(+) = add_double
(-) = subtract_double
(*) = multiply_double
abs = abs_double
negate = negate_double
signum = signum_double
fromInteger = integerToDouble
-- These may get used in other modules...
foreign import bpcall "Num:" intToInteger :: Int -> Integer
foreign import bpcall "Num:" intToDouble :: Int -> Double
foreign import bpcall "Prelude:" doubleToInt :: Double -> Int
|