Apparent contradiction in H98 prescribed behavior of 'data X =
(:+){ x :: Int, y :: Int } deriving(Show)'
Stefan O'Rear
stefanor at cox.net
Tue Apr 17 20:41:42 EDT 2007
Given:
data X = (:*){ x :: Int, y :: Int } deriving(Show)
which is syntactically correct:
> constr -> con { fielddecl[1] , ... , fielddecl[n] } (n>=0)
> con -> ( consym )
and the following from 10.4:
* If the constructor is defined to be an infix operator, then the
derived Read instance will parse only infix applications of the
constructor (not the prefix form).
* If the constructor is defined using record syntax, the derived
Read will parse only the record-syntax form, and furthermore,
the fields must be given in the same order as the original
declaration.
the behavor of the Show instance seems to be contradicted, since :+ is
an infix operator and is defined using record syntax.
Suggested resolution:
* If the constructor is defined using infix syntax, then the
derived Read instance will parse only infix applications of the
constructor (not the prefix form).
Thus, 'data X = Int :+ Int' would show infix but 'data X = (:+) Int
Int' would not.
Alternatively, change the con in the above production for constr to
conid, thus banning infix record constructors.
Status:
stefan at stefans:/tmp$ cat Main.hs
data X = (:*) { x :: Int, y :: Int } deriving(Show)
main = print ((:*) 2 2)
stefan at stefans:/tmp$ runghc Main.hs
(:*) {x = 2, y = 2}
stefan at stefans:/tmp$ runhugs Main.hs
:* {x = 2, y = 2}
stefan at stefans:/tmp$ yhc Main.hs
Compiling Main ( Main.hs )
stefan at stefans:/tmp$ yhi Main.hbc
2 :* 2
stefan at stefans:/tmp$
Note that the hugs output for this corner case is unparseable and thus
buggy!
Stefan
More information about the Haskell-prime
mailing list