[Haskell-cafe] Parsec bug, or...?

wren ng thornton wren at freegeek.org
Thu Oct 15 03:30:27 EDT 2009

Uwe Hollerbach wrote:
> Yes, I've looked at that and am thinking about it. I'm not quite
> certain it's needed in my real program... I seem to have convinced
> myself that if I actually specify a proper set of unique prefixes, ie,
> set the required lengths for both "frito" and "fromage" to 3 in the
> test program, I won't get into this situation. Assuming I haven't
> committed another brain-fart there, that would be sufficient;
> presumably, in a real program one would want to actually specify the
> unique prefix, rather than a non-unique pre-prefix. It seems to work
> fine in my real program, anyway.

Another approach ---assuming you're not wedded to Parsec--- would be to 
construct a trie, e.g. with bytestring-trie[1]. Then use 
Data.Trie.submap to look up the query. If the result is unique then you 
go with it, if not then list the submap's keys in your error message.

The big benefit of this approach is that you needn't maintain a list of 
lengths for disambiguating the keys, the trie does that for you.


Live well,

More information about the Haskell-Cafe mailing list