Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Writing an instance of Read? (Mike Meyer)
2. Re: Writing an instance of Read? (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Sat, 15 Oct 2011 17:15:54 -0700
From: Mike Meyer <[email protected]>
Subject: [Haskell-beginners] Writing an instance of Read?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
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,
<mike
--
Mike Meyer <[email protected]> http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
------------------------------
Message: 2
Date: Sun, 16 Oct 2011 02:42:30 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Writing an instance of Read?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
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,
> <mike
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.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 40, Issue 22
*****************************************