Folks,

Another small but long-standing bug in the Haskell Library report:
the recursive calls to 'reads' and 'shows' in the Read and Show
instances for Ratio and Array should be calls to readsPrec and showsPrec
respectively.  The corrected defintions are below.
(c.f. the example of derived instances in Appendix D of the language
report.)

Anyone disagree?   (How do these bugs last so long?)

Simon

================== Page 5 ========================
  instance  (Read a, Integral a)  => Read (Ratio a)  where
    readsPrec p  =  readParen (p > prec)
                              (\r -> [(x%y,u) | (x,s)   <- readsPrec
(prec+1) r,
                                                ("%",t) <- lex s,
                                                (y,u)   <- readsPrec
(prec+1) t ])

  instance  (Integral a)  => Show (Ratio a)  where
    showsPrec p (x:%y)  =  showParen (p > prec)
                               (showsPrec (prec+1) x . 
                                showString " % " . 
                                showsPrec (prec+1) y)


================== Page 24 ========================
  instance  (Ix a, Show a, Show b) => Show (Array a b)  where
    showsPrec p a = showParen (p > arrPrec) (
                    showString "array " .
                    showsPrec (arrPrec+1) (bounds a) . showChar ' ' .
                    showsPrec (arrPrec+1) (assocs a)                  )

  instance  (Ix a, Read a, Read b) => Read (Array a b)  where
    readsPrec p = readParen (p > arrPrec)
           (\r -> [ (array b as, u) 
                  | ("array",s) <- lex r,
                    (b,t)       <- readsPrec (arrPrec+1) s,
                    (as,u)      <- readsPrec (arrPrec+1) t ])

  -- Precedence of the 'array' function is that of application itself
  arrPrec = 10
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to