want better error msg with Class Read

Johannes Waldmann joe@isun.informatik.uni-leipzig.de
Thu, 7 Nov 2002 10:22:49 +0100 (MET)


Dear all, I would welcome some advice 
on getting better error messages
when using  read :: Read a => a

The problem is, `readsPrec' (the class method) 
eats the longest feasible input prefix,
but when I call `read' (built-in prelude function)
on a string that does not parse, but that has a valid prefix, I get this:

> Inter> readsPrec 0 "1 ) " :: [(Integer,String)]
> [(1," ) ")]
> Inter> read "1 )" :: Integer
> 
> Program error: Prelude.read: no parse

This is correct, but I would like to show (in the error message)
the prefix that *was* parsed as well.
If `read' was a class method, I could override it.
(Compare class Show, where there is the method `showsPrec',
but since H98 (?), `show' is a class method as well.)

In my application, the type to parse is not Integer,
but some expression type that might contain parentheses.
Its Read instance uses the Parsec library,
but I think this is irrelevant to the above question.

Best regards,
-- 
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/207 --