1

The .hs code :

data Person = Person { firstName :: String  
                     , lastName :: String  
                     , age :: Int  
                     } deriving (Eq, Show, Read)

Compilation :

*Main> :load "/home/optimight/baby.hs"  
[1 of 1] Compiling Main             ( /home/optimight/baby.hs, interpreted )  
Ok, modules loaded: Main.  

While testing immediately after compilation:

*Main> read "Person {firstName = \"Michael\", lastName \"Diamond\", age = 43}" :: Person  
*** Exception: Prelude.read: no parse

Please guide. Why this error is occurring and how to avoid such errors?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Optimight
  • 2,989
  • 6
  • 30
  • 48

1 Answers1

7
lastName \"Diamond\"

is missing an equals sign.

read "Person {firstName = \"Michael\", lastName = \"Diamond\", age = 43}" :: Person
Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
  • Sir, removed the error. The code is working now. Sorry, took your time for such small thing. – Optimight Jul 23 '12 at 12:04
  • 5
    No problem, didn't take much time. Since it wasn't mine, the typo jumped out quickly. As for "how to avoid such errors?", there is unfortunately no way, you will always make typos, like everybody else. – Daniel Fischer Jul 23 '12 at 12:08
  • 1
    Sir, I am encouraged (to learn more quickly) by your warm response. Thanks a lot. – Optimight Jul 23 '12 at 12:10