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

Misha Aizatulin avatar at hot.ee
Fri Aug 25 18:50:11 EDT 2006


hi,

  the Haskell Report 10.4 says that

"The result of show is readable by read if all component types are readable"

  however if I define a type like

data T = A | T `And` T deriving (Read, Show)

  then

*Main> show $ A `And` A
"A And A"
*Main> (read "A And A") :: T
*** Exception: Prelude.read: no parse
*Main>

  In fact, I wasn't able to guess, what I should type so that the value
(A `And` A) gets parsed.

  I have ghc 6.4.1. Looking into the code of the derived instance I see
that it expects Text.Read.Lex.lex to return (Symbol "And") for the
constructor. If I understand the code for lex correctly, then it parses
things as Symbol if they consist only of
"!@#$%&*+./<=>?\\^|:-~"

  How then do I read values of type T defined above? Thanks in advance
for any directions.

Cheers,
  Misha



More information about the Haskell-Cafe mailing list