ref: 638e7ca702c9c27bd58a72d68b0862c86e68c25b
dir: /lib/Data/Int.hs/
-- Copyright 2023 Lennart Augustsson
-- See LICENSE file for full license.
module Data.Int(module Data.Int, Int) where
import Primitives
import Data.Bool_Type
import Data.Char_Type
import Data.Eq
import Data.List_Type
import Data.Ord
import Text.Show
infixl 6 +,-
infixl 7 *,`quot`,`rem`
-- Arithmetic
(+) :: Int -> Int -> Int
(+) = primIntAdd
(-) :: Int -> Int -> Int
(-) = primIntSub
(*) :: Int -> Int -> Int
(*) = primIntMul
quot :: Int -> Int -> Int
quot = primIntQuot
rem :: Int -> Int -> Int
rem = primIntRem
subtract :: Int -> Int -> Int
subtract = primIntSubR
negate :: Int -> Int
negate x = 0 - x
--------------------------------
-- infix 4 ==,/=
--infix 4 <,<=,>,>=
-- Comparison
{-
(==) :: Int -> Int -> Bool
(==) = primIntEQ
(/=) :: Int -> Int -> Bool
(/=) = primIntNE
-}
instance Eq Int where
(==) = primIntEQ
(/=) = primIntNE
{-
(<) :: Int -> Int -> Bool
(<) = primIntLT
(<=) :: Int -> Int -> Bool
(<=) = primIntLE
(>) :: Int -> Int -> Bool
(>) = primIntGT
(>=) :: Int -> Int -> Bool
(>=) = primIntGE
-}
instance Ord Int where
(<) = primIntLT
(<=) = primIntLE
(>) = primIntGT
(>=) = primIntGE
--------------------------------
instance Show Int where
show = showInt
-- XXX these should not be exported
-- XXX wrong for minInt
showInt :: Int -> String
showInt n =
if n < 0 then
'-' : showUnsignedInt (negate n)
else
showUnsignedInt n
showUnsignedInt :: Int -> String
showUnsignedInt n =
let
c = primChr (primOrd '0' + rem n 10)
in if n < 10 then
[c]
else
showUnsignedInt (quot n 10) ++ [c]