[Haskell] readList oddity

Wolfgang Lux wlux at uni-muenster.de
Thu Oct 21 06:40:59 EDT 2004

Am 21.10.2004 um 09:55 schrieb Johannes Waldmann:

> turns out that check1 and check2 work, but check0 will not (I thought 
> it would). The implementation (in the Prelude) seems to think that "]" 
> (in check0) could possibly be the beginning of a list element.

This is just a problem of non-deterministic parsing. The prelude's read
function always explores all possible parses (in order to flag ambiguous
ones). Thus, at the beginning of the list it will always try to match 
input against ] and an element causing check0 to fail. For later 
there is no problem because the choice is between ] and ,.

Because of that, calling error in one of your read functions seems a bad
idea. In fact, returning an empty list is the right way to return an 
in the prelude's parsing framework. If you want something different 
because you want better error messages) you should not be using the 
read function. IMHO, the prelude's Read class for that reason is quite
useless -- except for converting strings into numbers.


More information about the Haskell mailing list