Hi
I've found the bugs in read and show that stop (read . show) from
working.
This is in hugs 1.4, the November 1998 beta.
They occur when showing data types with record syntax.

There are two bugs:
1 readField in the prelude should be as follows:
readField    :: Read a => String -> ReadS a
readField m s0 = [ r | (t,  s1) <- lex s0, t == m,
                       ("=",s2) <- lex s1,
                       r        <- reads s2 ]  *** instead of readsPrec
10

this makes it consistent with showField
showField    :: Show a => String -> a -> ShowS
showField m v = showString m . showChar '=' . shows v

2 constructors with record syntax when printed should be bracketed:
That is, in static.c the code for showing record syntax should be as
follows.
(changed lines are marked with a ***).
This makes it consistent with reading record syntax.

 /* To display a value using record syntax:
  *    showParen (d>=10)  ***
  *        (showsPrec d C{x=e, y=f, z=g} = showString "C"  . showChar
'{' .
  *         showField "x" e . showChar ',' .
  *         showField "y" f . showChar ',' .
  *         showField "z" g . showChar '}')
  *    showField lab val
  *       = showString lab . showChar '=' . shows val
  */
 Cell rhs     = showsCB;
 List vs      = dupOnto(snd(hd(cfs)),NIL);
 if (isAp(pat)) {
     for (;;) {
  rhs = ap2(nameComp,
     ap2(nameShowField,
         mkStr(textOf(hd(vs))),
         arg(pat)),
     rhs);
  pat = fun(pat);
  vs  = tl(vs);
  if (isAp(pat))
      rhs = ap(showsCM,rhs);
  else
      break;
     }
 }
 rhs = ap2(nameComp,ap(nameApp,mkStr(name(h).text)),ap(showsOB,rhs));
 rhs = ap2(nameShowParen,ap2(nameLe,mkInt(10),d),rhs); ***
 return rhs;



--
Meurig Sage
Dept of Computing Science
University of Glasgow
http://www.dcs.gla.ac.uk/~meurig
mailto:[EMAIL PROTECTED]


Reply via email to