Deal correctly with infix type constructors in GADT decls
[ghc-hetmet.git] / compiler / ilxGen / tests / PrelNum.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 {-# OPTIONS -fglasgow-exts -fno-implicit-prelude #-}
18
19 module PrelNum where
20
21 import {-# SOURCE #-} PrelErr
22 import PrelBase
23 import PrelList
24 import PrelEnum
25 import PrelShow
26
27 infixl 7  *
28 infixl 6  +, -
29
30 default ()              -- Double isn't available yet, 
31                         -- and we shouldn't be using defaults anyway
32
33
34
35
36
37
38
39
40
41 class  (Eq a, Show a) => Num a  where
42     (+), (-), (*)       :: a -> a -> a
43     negate              :: a -> a
44     abs, signum         :: a -> a
45     fromInteger         :: Integer -> a
46     fromInt             :: Int -> a -- partain: Glasgow extension
47
48     x - y               = x + negate y
49     negate x            = 0 - x
50     fromInt (I# i#)     = fromInteger (S# i#)
51                                         -- Go via the standard class-op if the
52                                         -- non-standard one ain't provided
53
54
55
56
57
58 subtract        :: (Num a) => a -> a -> a
59 {-# INLINE subtract #-}
60 subtract x y    =  y - x
61
62 ord_0 :: Num a => a
63 ord_0 = fromInt (ord '0')
64
65
66
67
68
69
70
71
72
73
74 instance  Num Int  where
75     (+)    x y =  plusInt x y
76     (-)    x y =  minusInt x y
77     negate x   =  negateInt x
78     (*)    x y =  timesInt x y
79     abs    n   = if n `geInt` 0 then n else (negateInt n)
80
81     signum n | n `ltInt` 0 = negateInt 1
82              | n `eqInt` 0 = 0
83              | otherwise   = 1
84
85     fromInt n     = n
86
87
88
89
90 -- These can't go in PrelBase with the defn of Int, because
91 -- we don't have pairs defined at that time!
92
93 quotRemInt :: Int -> Int -> (Int, Int)
94 a@(I# _) `quotRemInt` b@(I# _) = (a `quotInt` b, a `remInt` b)
95     -- OK, so I made it a little stricter.  Shoot me.  (WDP 94/10)
96
97 divModInt ::  Int -> Int -> (Int, Int)
98 divModInt x@(I# _) y@(I# _) = (x `divInt` y, x `modInt` y)
99     -- Stricter.  Sorry if you don't like it.  (WDP 94/10)
100
101
102
103
104
105
106
107
108
109
110 data Integer    
111    = S# Int#                            -- small integers
112    | J# Int# ByteArray#                 -- large integers
113
114
115
116
117
118 zeroInteger :: Integer
119 zeroInteger = S# 0#
120