f6037123b09ebe9d99939bc3c2114060e59dd9a4
[ghc-hetmet.git] / ghc / tests / specialise / code003 / PreludeNum.hs
1 module PreludeNum (
2
3         double, compute1, compute2
4
5     ) where
6
7 {- Preliminaries ... -}
8
9 {- patError# { Int# } (built into compiler) -}
10 local_map f []     = []
11 local_map f (x:xs) = (f x) : local_map f xs
12
13
14 {- Here we go ... -}
15
16 instance  Eq Int#  where
17     x == y = eqInt# x y
18     x /= y = neInt# x y
19
20 instance  Read Int#  where
21     readsPrec p s = map (\ (I# i#, s) -> (i#, s)) (readsPrec p s)
22     readList s = map (\ (x, s) -> (local_map (\ (I# i#) -> i#) x, s)) (readList s)
23
24 instance  Show Int#  where
25     showsPrec p x = showsPrec p (I# x)
26     showList l = showList (local_map I# l)
27
28 instance  Num Int#  where
29     (+)    x y =  plusInt# x y
30     (-)    x y =  minusInt# x y
31     negate x   =  negateInt# x
32     (*)    x y =  timesInt# x y
33     abs    n   = if n `geInt#` 0# then n else (negateInt# n)
34
35     signum n | n `ltInt#` 0# = negateInt# 1#
36              | n `eqInt#` 0# = 0#
37              | otherwise     = 1#
38
39     fromInteger (J# a# s# d#)
40       = integer2Int# a# s# d#
41
42     fromInt (I# i#) = i#
43
44 double x = x * x + x * x - x * x + x * x - x * x
45
46 compute1 n = 1# + double n
47 compute2 n = (1::Int) + double n
48
49
50