[Haskell-cafe] Re: Derived Read instance for types with infix constructors (ghc 6.4.1)

Jason Dagit dagit at eecs.oregonstate.edu
Sat Aug 26 15:23:50 EDT 2006

On 8/26/06, Misha Aizatulin <avatar at hot.ee> wrote:
> Neil Mitchell wrote:
> >> *Main> show $ A `And` A
> >> "A And A"
> >
> > For me, using GHCi 6.4.2 + Windows, I get:
> > "A `And` A"
>   I installed GHC 6.4.2 now (on Linux). It really does print "A `And`
> A", but still doesn't read it. Would you agree that GHC doesn't conform
> to the Haskell Report here? In fact it seems to produce a Read instance
> with no valid input for it!

I would agree that this is a flaw.

> Daniel Fischer wrote:
> > Put the constructor in the prefix position in the data definition and
> > the derived Read instance of ghc 6.4.1 will also be able to read the
> > prefix form.
>   This might be a solution, but I was hoping that I can have a Read
> instance that would read the infix form - this would be more natural for
> the data I have (like logical expressions).

Before you get too caught up in deriving Read, remember that in
Haskell it's very easy to create your own custom parser.  Assuming you
have previous experience with happy or parsec you could probably have
already created a custom parser with time you've spent debugging this
automatic Read instance flaw.  And if you had your own parser couldn't
you define read to use that parser?  Just a thought...


More information about the Haskell-Cafe mailing list