On Thu, 7 Nov 2002, Johannes Waldmann wrote:
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.)
Why not just define your own function, much like `read`, that produces a more suitable error message? -- Dean