Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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 <m...@mired.org>
Subject: [Haskell-beginners] Writing an instance of Read?
To: beginners@haskell.org
Message-ID: <20111015171554.7a9ac...@bhuda.mired.org>
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 <m...@mired.org>             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 <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] Writing an instance of Read?
To: beginners@haskell.org
Message-ID: <201110160242.30906.daniel.is.fisc...@googlemail.com>
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
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 40, Issue 22
*****************************************

Reply via email to