[Haskell-cafe] Names in a record changes read behavior?

Mike Meyer mwm at mired.org
Mon Jul 27 20:25:44 UTC 2015


Ok, this all works as expected:

λ> data Point = Point Float Float deriving (Show, Read)
λ> Point 1.0 1.0
Point 1.0 1.0
λ> read "Point 1.0 1.0"
*** Exception: Prelude.read: no parse
λ> read "Point 1.0 1.0" :: Point
Point 1.0 1.0

But now we add names to the values in the Point, and things change:

λ> data Point = Point {x :: Float, y :: Float } deriving (Show, Read)
λ> Point 1.0 1.0
Point {x = 1.0, y = 1.0}
λ> read "Point 1.0 1.0"
*** Exception: Prelude.read: no parse
λ> read "Point 1.0 1.0" :: Point
*** Exception: Prelude.read: no parse
λ> read "Point {x = 1.0, y = 1.0 }" :: Point
Point {x = 1.0, y = 1.0}

OK, why won't read accept the same syntax as the REPL? I can see wanting
Read and Show to be inverses of each other, though I think it's a bit
misguided. But if we're going to be that strict about them being inverses,
shouldn't we also insist that the READ eval print loop only accept what
read will accept?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150727/175954ea/attachment.html>


More information about the Haskell-Cafe mailing list