1 module PreludeNum (f1, f2, fac, f3, fac_two) where
3 {- Preliminaries ... -}
5 {- patError# { Int# } (built into compiler) -}
7 local_map f (x:xs) = (f x) : local_map f xs
13 instance Read Int# where
14 readsPrec p s = map (\ (I# i#, s) -> (i#, s)) (readsPrec p s)
15 readList s = map (\ (x, s) -> (local_map (\ (I# i#) -> i#) x, s)) (readList s)
17 instance Show Int# where
18 showsPrec p x = showsPrec p (I# x)
19 showList l = showList (local_map I# l)
21 instance Num Int# where
22 (+) x y = plusInt# x y
23 (-) x y = minusInt# x y
24 negate x = negateInt# x
25 (*) x y = timesInt# x y
26 abs n = if n `geInt#` 0# then n else (negateInt# n)
28 signum n | n `ltInt#` 0# = negateInt# 1#
32 fromInteger (J# a# s# d#)
33 = integer2Int# a# s# d#
44 fac n = n * (fac (n - 1))
51 fac_two n two = case n of 0 -> (1, 1)
52 n -> (n * (first (fac_two (n - 1) two)), 2)
54 f3 = let (res1, two1) = fac_two (10::Int#) (two2::Int#)
55 (res2, two2) = fac_two (10::Int) (two1::Int)