
Is there a tutorial - or anything at all, for that matter - on writing
Read instances? Particularly so that it integrates properly types that
incoporate your type and derive Read? Real World Haskell gives one
simple example (which doesn't use the first argument), points out one
problem with the example, then says "many people find it easier to use
Parsec." And that's the best such I could find.
Thanks,

On Sunday 16 October 2011, 02:15:54, Mike Meyer wrote:
Is there a tutorial - or anything at all, for that matter - on writing Read instances? Particularly so that it integrates properly types that incoporate your type and derive Read? Real World Haskell gives one simple example (which doesn't use the first argument), points out one problem with the example, then says "many people find it easier to use Parsec." And that's the best such I could find.
Thanks,
If you're using GHC, you can directly use Text.ParserCombinators.ReadPrec and Text.ParserCombinators.ReadP to write your Read instances (define readPrec and optionally readListPrec instead of readsPrec and readList). If your parser is correct, it will automatically integrate properly with derived Read instances. ReadP has many combinators in common with Parsec, so going from Parsec to ReadP is fairly straightforward.
participants (2)
-
Daniel Fischer
-
Mike Meyer