> Can anyone spot the fault in the derived instance of Read produced
> by DrIFT?
> 
> Regards,
>     Malcolm
> 
> > data List a = Nil | Cons { hd :: a, tl :: List a }
> >
> > {-* Generated by DrIFT-v1.0 : Look, but Don't Touch. *-}
> > instance (Show a) => Show (List a) where
> >     showsPrec d (Nil) = showString "Nil"
> >     showsPrec d (Cons aa ab) = showParen (d >= 10)
> >           (showString "Cons" . showChar '{' .
> >            showString "hd" . showChar '=' . showsPrec 10 aa . showChar ',' .
> >            showString "tl" . showChar '=' . showsPrec 10 ab
> >            . showChar '}')
> > 
> > instance (Read a) => Read (List a) where
> >     readsPrec d input =
> >           (\ inp -> [((Nil) , rest) | ("Nil" , rest) <- lex inp]) input
> >           ++
> >           readParen (d > 9)
> >           (\ inp ->
> >            [((Cons aa ab) , rest) | ("Cons" , inp) <- lex inp ,
> >             ("{" , inp) <- lex inp , ("hd" , inp) <- lex inp ,
> >             ("=" , inp) <- lex inp , (aa , inp) <- readsPrec 10 inp ,
> >             ("," , inp) <- lex inp , ("tl" , inp) <- lex inp ,
> >             ("=" , inp) <- lex inp , (ab , inp) <- readsPrec 10 inp ,
> >             ("}" , rest) <- lex inp])
> >           input

Since the Report states that the derived Show instances only insert
parentheses where needed and that the derived Read instances can
read the output produced by show, I would suggest to change all
occurences of {showsPrec 10,readsPrec 10} to {showsPrec 0,readsPrec 0}
in the above code.

Best,
  Andres

-- 

Andres Loeh, Universiteit Utrecht

mailto:[EMAIL PROTECTED]     mailto:[EMAIL PROTECTED]
http://www.andres-loeh.de

_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to