\begin{code}
data (Integral a) => Ratio a = !a :% !a deriving (Eq)
+
+-- | Arbitrary-precision rational numbers, represented as a ratio of
+-- two 'Integer' values. A rational number may be constructed using
+-- the '%' operator.
type Rational = Ratio Integer
+ratioPrec, ratioPrec1 :: Int
+ratioPrec = 7 -- Precedence of ':%' constructor
+ratioPrec1 = ratioPrec + 1
+
infinity, notANumber :: Rational
infinity = 1 :% 0
notANumber = 0 :% 0
instance (Integral a) => Show (Ratio a) where
{-# SPECIALIZE instance Show Rational #-}
- showsPrec p (x:%y) = showParen (p > ratio_prec)
- (shows x . showString " % " . shows y)
-
-ratio_prec :: Int
-ratio_prec = 7
+ showsPrec p (x:%y) = showParen (p > ratioPrec) $
+ showsPrec ratioPrec1 x .
+ showString " % " .
+ showsPrec ratioPrec1 y
instance (Integral a) => Enum (Ratio a) where
{-# SPECIALIZE instance Enum Rational #-}