
On Mon, Jul 27, 2015 at 1:25 PM, Mike Meyer
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}
This works because the type of Point is Point :: Float -> Float -> Point. You could have equally written:
let foo = Point foo 1.0 1.0
The parser at the REPL is looking for arbitrary Haskell expressions, and "Point 1.0 1.0" just happens to be a function application expression. I hope that helps, Jason